This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-05-05 17:00:23

Cozyhut3
Scratcher
Registered: 2010-02-06
Posts: 500+

Rope/Line Physics

I've been struggling with this one for a while. I haven't tried it, but I have no idea where to start. It would be very useful in future projects, but has been accomplished only TWICE in Scratch history, as far as I know. Only some really smart scratcher could know the answer to this one!  hmm  So, here's the question.. how do you create ROPE PHYSICS? 0_0'

Offline

 

#2 2012-05-05 17:40:56

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Rope/Line Physics

This is a great question, and I myself am interested in the answer.  For what it's worth, I think ropes follow a parabola-based form.

Oh, I actually just had an idea.  If you know the slope of the rope at the point where it is attached to a stationary item (where it is "knotted") and the slope of where it is tied to, you could presumably use calculus like this:

Code:

x1 = x position of one end
s1 = slope of one end
x2 = x position of other end
s2 = slope of other end
y1 = y position at x1 (where it is knotted)
derivative of the parabola = a linear line with the coordinates (x1,s1), and (x1,s2).

m = ((s1-s2) / (x1-x2)) (of course, this breaks when x1=x2, but an if-statement can take care of that)
b = y1 - (x1 * m)
derivative = mx + b
C = y1 - (0.5m(x1^2) + bx1)

answer:
actual parabola = 0.5m(x^2) + bx + C

Check my math please.

And I know that this isn't a complete answer (there is still the question of how you find the slopes at the two points), but it is hopefully part of the solution.

Edit: I may have been unclear, so this is the whole answer:

Code:

if m = ((s1-s2) / (x1-x2)) and b = y1 - (x1 * m)
The equation of the rope = 0.5x(X^2) + bX + (y1 - (0.5m(x1^2) + bx1))

Double Edit: the problem with this is that this only works when the rope is at rest and ignores things like momentum  hmm

Last edited by MoreGamesNow (2012-05-05 17:55:30)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#3 2012-05-05 19:28:34

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Rope/Line Physics

Rope physics are tricky.  You can never create a true "rope," you'll have to break it up into segments.  Keep in mind that every segment of the rope has mass, and affects every other segment. 

This article has a pretty in-depth description of the math behind it.

Offline

 

#4 2012-05-05 20:13:48

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Rope/Line Physics

Oh, looks like I was wrong about it being a parabola.  Turns out it is a "catenary", which I hadn't heard of until today.  Absolutely no idea what a catenary is, and I'm a little too busy to actually go searching, but I'm still interested in what you guys come up with.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#5 2012-05-06 12:35:19

Cozyhut3
Scratcher
Registered: 2010-02-06
Posts: 500+

Re: Rope/Line Physics

MoreGamesNow wrote:

This is a great question, and I myself am interested in the answer.  For what it's worth, I think ropes follow a parabola-based form.

Oh, I actually just had an idea.  If you know the slope of the rope at the point where it is attached to a stationary item (where it is "knotted") and the slope of where it is tied to, you could presumably use calculus like this:

Code:

x1 = x position of one end
s1 = slope of one end
x2 = x position of other end
s2 = slope of other end
y1 = y position at x1 (where it is knotted)
derivative of the parabola = a linear line with the coordinates (x1,s1), and (x1,s2).

m = ((s1-s2) / (x1-x2)) (of course, this breaks when x1=x2, but an if-statement can take care of that)
b = y1 - (x1 * m)
derivative = mx + b
C = y1 - (0.5m(x1^2) + bx1)

answer:
actual parabola = 0.5m(x^2) + bx + C

Check my math please.

And I know that this isn't a complete answer (there is still the question of how you find the slopes at the two points), but it is hopefully part of the solution.

Edit: I may have been unclear, so this is the whole answer:

Code:

if m = ((s1-s2) / (x1-x2)) and b = y1 - (x1 * m)
The equation of the rope = 0.5x(X^2) + bX + (y1 - (0.5m(x1^2) + bx1))

Double Edit: the problem with this is that this only works when the rope is at rest and ignores things like momentum  hmm

Erm.. I'm only thirteen..  tongue  I don't exactly get what you're saying, but I was able to read through that second mathematical string somewhat-clearly.

Offline

 

#6 2012-05-06 14:31:05

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Rope/Line Physics

Cozyhut3 wrote:

Erm.. I'm only thirteen..  tongue  I don't exactly get what you're saying, but I was able to read through that second mathematical string somewhat-clearly.

As I said above, the true curve is a "catenary", and my script represents it as a polynomial (though, if I understand it correctly, polynomials are often used to approximate catenaries anyway).  If you're thinking of using my math-stuff, here is why you should know:

My script will make a polynomial that has a Y position at the two ends of the rope, with the slopes of s1 and s2 at both ends.  So the slope at (x1,y1) is "s1" and the slope at (x2,y2) is "s2".  The problem (of course) comes from knowing what to make the slopes at both ends.  Actually, to be perfectly honest, I would pretty much disregard what I said and try to approximate it with multiple sprites recommending segments, as mine only describes the string at rest (and even then, inaccurately, because it isn't a catenary).  This problem is interesting, give me a bit and I'll get back to you.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#7 2012-05-06 15:30:54

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Rope/Line Physics

I've made a project that does an okay job at simulating it, though it is far from perfect.  Do you want me to upload it?


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#8 2012-05-06 18:14:43

Cozyhut3
Scratcher
Registered: 2010-02-06
Posts: 500+

Re: Rope/Line Physics

MoreGamesNow wrote:

I've made a project that does an okay job at simulating it, though it is far from perfect.  Do you want me to upload it?

Let me see what you've got.

Offline

 

#9 2012-05-06 18:30:42

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Rope/Line Physics


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

Board footer