1

I want to make a pendulum. I have a line with a ball fixed to both ends of the line. Ball1 is fixed in place. I want ball2 to "fall" (move down the screen) and I want it to "swing" on the line. AKA I want the ball to move down and I want the line to stay at a constant length forcing the ball to arc and "swing" on the line.

`
Part part1;
Part part2;
Muscle muscle1;
float gravity = 10;

void setup() {
  ...
}

void draw() {
  background(255);
  part1.drawpart();
  part2.drawpart();
  muscle1.drawmuscle(part1, part2);
  part2.movepart();
}

class Muscle{
  float leftx;
  float lefty;
  float rightx;
  float righty;
  float size = 100;
  int musclecolor;
  
  ...
  
  void drawmuscle(Part obj1, Part obj2) {
    strokeWeight(5);
    line(obj1.x, obj1.y, obj2.x, obj2.y);
    size = sqrt(sq(obj1.x - obj2.x) + sq(obj1.y - obj2.y)); 

^^ This is the equation to keep the line the same length. Will this equation work if placed in the right location? Or is this method just not possible?

  }
}

class Part{
  float x;
  float y;
  float size;
  int partcolor;
  
  ...
  void drawpart() {
    ...
    ellipse(x, y, size, size);
  }
  
  void movepart() {
   part2.y += gravity;
  }
}
  • This seems to be a simillar question but is a little complicated for me so I don't understand it. I know what binomial coefficients are but I'm not sure how this answers the question. https://stackoverflow.com/questions/70793859/how-do-i-oscillate-the-height-of-individual-shapes-whilst-keeping-the-total-heig – William Chandler Mar 28 '22 at 17:59
  • Is this only realistically possible using angles? – William Chandler Mar 28 '22 at 18:48
  • As you probably heard before, programming and math goes hand in hand. The length of the line will help you calculate where the ball is, but you'll need to calculate it's position anyway. [Here is a good post on how to calculate the coordinates of a point on a circle using the current angle of said point](https://math.stackexchange.com/questions/260096/find-the-coordinates-of-a-point-on-a-circle) as you seem to be willing to work with angles. – laancelot Mar 28 '22 at 21:16
  • @laancelot yea I was literally a math major and I still can barely remember all the math necessary for programming lol. Thanks again for all your help. – William Chandler Mar 29 '22 at 14:49

0 Answers0