Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Placing an object along a path

Author
Message
anwserman
13
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 8th Aug 2013 09:25
Anyone have a good idea on how to do this?

Let's say my path is like so:

What would be the best way to determine where an object goes, let's say I want it placed at the 63% mark? Right now, this is what I have:

1) I know I'd need an array of points
2) Find the length of each segment (between points)
3) Compute the sum of all segments
4) Determine which percentage range each segment covers
5) Somehow magically turn a global percentage (63%) and convert it to a percentage among the correct segment

Does this seem correct?

Hi there. My name is Dug. I have just met you, and I love you.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 8th Aug 2013 10:35
i suggest you fill the array (udt with pos.,angle) with all steps included between
your points, then the upper bound of your array is 100%

alternatively use some interpolation algorithm,
there often is used a float value from 0.0 to 1.0 as 0-100%.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 8th Aug 2013 22:35
I would suggest making the points which create the path be evenly distributed. That would make calculating a specific point much easier using linear interpolation.


If your path is made up of 10 points, and point A(start) is at [0,0] and point B(end) is at [400,0], then each point is 40px(400/10) apart.

You want to find 63%? Represented as a float in the range of 0 to 1: 0.63

Multiply 0.63 by the length of your path, 400. You end up with 252px. Now assuming your path isn't a flat line and there is a variable height from point to point, to calculate the height of the path at 252px along the x-axis we need to know which two points in the path this position falls into.

Each segment between points in this example is 40px, so divide that into the 252 we calculated. You'll get 6.3. Only use the integer portion at this moment to get the starting point, which is 6.

Your target point 63% along the path lies between point 6 and 7. Point 6 starts at 240px (6*40). Subtract that from 252 and you'll have 12. That's 12px along the 40px segment, or 30% passed point 6 (12/40=0.3).

AY and BY represent the heights of point 6 and point 7.
Y = AY + (BY - AY)*0.3

So your target point at 63% along the path is:
X = 252
Y = AY + (BY - AY)*0.3


It'd probably be easier to follow if I drew some pictures, but hopefully you got the gist of it.

3d point in space
15
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 9th Aug 2013 00:39
this is something I pulled from what I made 2 years ago.


Developer of Space Chips, pianobasic, zipzapzoom, and vet pinball apps. Developed the tiled map engine seen on the showcase. Veteran for the military.

Login to post a reply

Server time is: 2024-11-24 18:05:05
Your offset time is: 2024-11-24 18:05:05