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! So, here's the question.. how do you create ROPE PHYSICS? 0_0'
Offline
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:
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:
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
Last edited by MoreGamesNow (2012-05-05 17:55:30)
Offline
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
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.
Offline
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 + CCheck 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
Erm.. I'm only thirteen.. I don't exactly get what you're saying, but I was able to read through that second mathematical string somewhat-clearly.
Offline
Cozyhut3 wrote:
Erm.. I'm only thirteen.. 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.
Offline
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?
Offline