Points on a 3d line

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
markanderson
Posts: 30
Joined: Thu Mar 16, 2006 6:21 pm

Points on a 3d line

Post by markanderson »

Hello All -

I seek the wisdom of the Irrlicht oracles... again ;]

My app draws a straight line linking 2 points in 3D space. But I need to dynamically find X number of points along that line (preferably equally spaced along the line). I have tried several different approaches but without much success. I just lack the 3D math skill I think.

Can anyone point me in the right direct?

Thanks,

Mark.
Dances
Posts: 454
Joined: Sat Jul 02, 2005 1:45 am
Location: Canada
Contact:

Post by Dances »

I would use the getLength function and divide it for however many points you desire, then you can locate the points following the line for a specified distance.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Get the length of the line and divide that by the number of segments you want to split it up into. That will get you the distance between points.

Code: Select all

const f32 distance_between_points = line.getLength() / number_of_points;
For each of the points, take the point number and multiply that by the normal of the line and multiply it by the distance between points. That gets you the offset from the start of the line for that point.

Code: Select all

const core::vector3df normal_of_line = line.getVector().getNormal();

u32 p;
for (p = 0; p < number_of_points; ++p)
{
  const core::vector3df offset_from_start = normal_of_line * (p * distance_between_points);
Then add that to the start of the line.

Code: Select all

  const core::vector3df point = line.start + offset_from_start;
}
FlyingIsFun1217
Posts: 219
Joined: Fri Apr 13, 2007 8:29 pm
Location: Illinois
Contact:

Post by FlyingIsFun1217 »

Yeah, probably just kinda what these guys said, but from what I learned in Algebra2 this year (working on ellipses stuff, especially), you have the formula of the line, and solve for point x units to right/left/top/bottom.

I'm sure there are easier ways though ;)

FlyingIsFun1217
Post Reply