#### Archived

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

# Intersection of two line segments

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

## Recommended Posts

How do I find the intersection of two line segments in 3D?

##### Share on other sites
I don''t know if this will work, I''m still sorta new to 3d game programming but in my head this seems like it would work
with a vector class that contains a Position Struct named Pos.
Try this

FindIntersection(Vector1, Vector2)
{
While(Vector1.Pos != Vector2.Pos)
{
Vector1.Move();
}
Return X,Y,Z;
}

The "Move()" function would be an algorhythm that would trace along the path of the vector. This might be what you are having trouble with.. it may be simillar to an AI function for moving a monster closer to a player, e.g.
if(Vector1.X < Vector2.X)
//Change observing position..

do the same for .Y and .Z

I hope it helps

Kris
ForceFedDrummer

##### Share on other sites
A line in 3 space is defined can be defined by parametic equations.

x = x0 + at
y = y0 + bt
z = z0 + ct

where the point (x0, y0, z0) is on the line
and the vector <a, b, c> is parallel to the line.
If you find the equations for two lines then just set the x
and y equations equal to each other and solve for t. Plug the value of t into the z equations and see if they are equal. If the z equations do not match then the lines do not intersect.

##### Share on other sites
just thought I should point out- don''t do what Kris said, the algebraic solution is infinitely superiour.

thanks!

1. 1
Rutin
22
2. 2
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633308
• Total Posts
3011293
• ### Who's Online (See full list)

There are no registered users currently online

×