Jump to content
• Advertisement

#### Archived

This topic is now archived and is closed to further replies.

# Need an algorithm for a simple problem!!

This topic is 6212 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

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

#### Share this post

##### Share on other sites
Advertisement
Check out this site. http://freespace.virgin.net/hugo.elias/
There''s an article on how to program string that might help.

#### Share this post

##### Share on other sites
afaik the function you need is the cosine hyperbolicus
cosh(x) = (exp(x)+exp(-x))/2

#### Share this post

##### Share on other sites
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."

#### Share this post

##### Share on other sites
Is it possible to use D3DXVec3Hermite to solve your problem? It''s at least simple.

#### Share this post

##### Share on other sites
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

#### Share this post

##### Share on other sites
Scoop> Thanks, I''ll try that

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

#### Share this post

##### Share on other sites
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

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

#### Share this post

##### Share on other sites
Just off the top of my head

  p = CurrentLength/RopeLength - gives the ratio of length shrinkagefor(i=0;i

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?

#### Share this post

##### Share on other sites
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.

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
3. 3
frob
15
4. 4
5. 5
• Advertisement

• 20
• 12
• 13
• 14
• 83
• ### Forum Statistics

• Total Topics
632144
• Total Posts
3004413

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!