Need an algorithm for a simple problem!!

Started by
11 comments, last by MindWipe 22 years, 8 months ago
I need some kinda algorithm for this problem. I have x1 and x2 and between them is a rope. Look at this picture to give you a better idea: I have tried to solve it by subtracting an acceleration in the beginning and end like this: ..... . . . . . . . . . . . ..... and then lowering it in the same way, but I haven't succeeded. I just need a for-loop or something that would first lower the points. Let's say we have 50
  
for(i=0;i<50;i++)
{
point[i].x = ?????
point[i].y = ?????
}

And I can't make it like:
k=20;
point[1].y+=k;
k--;
point[2].y+=point[1].y+k;
k--;
point[3].y+=point[2].y+k;
  
because then there will be less points in the beginning and there will be holes between the "balls" that the rope is made of(fig. 4). How would you do it. Pleease help, it has been bothering me for days /MindWipe "If it doesn't fit, force it; if it breaks, it needed replacement anyway." Edited by - MindWipe on August 10, 2001 10:18:44 AM
"To some its a six-pack, to me it's a support group."
Advertisement
Check out this site. http://freespace.virgin.net/hugo.elias/
There''s an article on how to program string that might help.
afaik the function you need is the cosine hyperbolicus
cosh(x) = (exp(x)+exp(-x))/2
monkey8751> Thanks for the info. But it would be a bit too hard to use. And I don''t think it has the solution for my problem. it''s more on how do create a ninjarope

diego_rodriguez> How do I use that in reality? Where''s the x1, x2, y?


Anyone know an easy solution?


"If it doesn''t fit, force it; if it breaks, it needed replacement anyway."
"To some its a six-pack, to me it's a support group."
Is it possible to use D3DXVec3Hermite to solve your problem? It''s at least simple.
Hi,

I would rather agree with the cosh. I would try to use
the cosinus (or in your case since the bride is hanging down: -cos), preferably with a lookup-table.

So here is ''my'' formula suggestion:

y = - MAX * cos(L*n);

where

- MAX = the ''height'' of the point right in the middle, meaning the maximum amplitude.

- L = PI / (number of points-1).

- n = the point number whose height to calculate.

Good luck

Scoop
Scoop
Scoop> Thanks, I''ll try that

"If it doesn''t fit, force it; if it breaks, it needed replacement anyway."
"To some its a six-pack, to me it's a support group."
Thanks Scoop. Got it working.

I had to add PI/2, otherwice it started on wrong location in the period.

Thanks alot.

Still one problem. The X.
That's a real tricky one. Because when the distance between x1 and x2 gets shorter, the ropes Xs needs to be nearer eachother.

It works if I take the RopeLength-CurrentLength(between x1 & x2)/amount of points

And then do:
  p= RopeLength-CurrentLength(between x1 & x2) / amount of points;for(i=0;i<amountofpoints;i++){point[i].x=(2.0f-p)*i; (I have 2 pixels between every point/ball)}  


but when the rope start to look like a U I need more points in the beginning and end.
So the X need to look like:

***** * * * * * * * * * * * * * * * * *****

You can see this in my image.

So my idea would make it accelerating and then deaccelerating
using:
by starting from 0 and going to:
2*RopeLength-CurrentLength(between x1 & x2) / amount of points;

But when the distance was less then half the size of the rope it went funny.

How would you do THIS?

/MindWipe


"If it doesn't fit, force it; if it breaks, it needed replacement anyway."

Edited by - MindWipe on August 10, 2001 1:53:54 PM
"To some its a six-pack, to me it's a support group."
Just off the top of my head

  p = CurrentLength/RopeLength   - gives the ratio of length shrinkagefor(i=0;i<numOfPoints;i++){    points[i].x = 2.0f*i*p;}  


2*i gives the normal length, but multiplying by p will decrease x accordingly since 0 < p < 1.

Instead of using cos + pi/2, why don''t you use sin?
A note on using cosine and sin. Those are hefty calculations and while this was true a few years ago when cpu''s sucked, these calculations take some time to calculate. You might want to make a sine/cosine ref table in memory that has a small resolution so to increase speed but you''ll only be able to do aprox calculations. Then again aprox calcs don''t really matter in a game. You might latter on, if you do alot of these calulations, notice a speed hit. So keep this in mind.
-Scott

This topic is closed to new replies.

Advertisement