Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ π -¹ ² ³ °

You are not logged in.

- Topics: Active | Unanswered

Pages: **1**

**safra****Member**- Registered: 2005-12-03
- Posts: 41

Hello!

I found out how to check if a line intersects with a triangle but actually it turns out that, in the case of "yes", I also need the intersection point.

Does someone have a quick way to find this vertice?

Thanks,

Raoul

Offline

**Ricky****Moderator**- Registered: 2005-12-04
- Posts: 3,791

What is your equation for the line? Parametric?

What is your equation for the triangle? Vectors?

Which vertices of the triangle do you wish to find? There are two where the line intersects the side of the triangle. Both?

The line also intersect both sides of the triangle, unless it is tangent to a vertice. Is this what you mean?

"In the real world, this would be a problem. But in mathematics, we can just define a place where this problem doesn't exist. So we'll go ahead and do that now..."

Offline

**safra****Member**- Registered: 2005-12-03
- Posts: 41

Sorry, This is a line / triangle intersection in a 3D world (directx). Actually what I need to find out is the y position of a landscape at a given position for x and z. so I can place an object on the landscape. A landscape is simply a huge number of vertices. 3 vertices connected to eachother (triangle) form a face. So my thought was, if I make a vertical line with known x and z values and a low and high y value I should be able to find the y value of the landscape at intersection point.

I found this piece of code: http://www.angelfire.com/fl/houseofbartlett/solutions/line2tri.html#Code

But actually this is a bit more complex. I only have access to vertice positions. If I first search for the 3 vertices of which the x and z values are closest to the x and z values of the line and if I then check whether the line is inside the triangle formed by these 3 vertices, will it be certain that these 3 triangles do actualy form a face? I think not. I guess I will have to experiment with this and see how accurate it is in bumpy areas of the landscape.

Offline

**safra****Member**- Registered: 2005-12-03
- Posts: 41

I started this thread a while ago and thought I found the answer, I guess not as it doesn't work.

Anyone knows a fast way to test if a vertical line intersects the triangle formed by 3 points and if so, find the intersection point?

Thanks,

Raoul

Offline

Pages: **1**