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.
Points on a 3d line
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.
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.
Then add that to the start of the line.
Code: Select all
const f32 distance_between_points = line.getLength() / number_of_points;
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);
Code: Select all
const core::vector3df point = line.start + offset_from_start;
}
-
- Posts: 219
- Joined: Fri Apr 13, 2007 8:29 pm
- Location: Illinois
- Contact: