Try taking the cross product of the triangle’s normal vector and the edge vector.

Please log in or register to post a reply.

oh, that was simple, thanks!

I have another one. Having a point on the triangle, how do you find the nearest edge from the point, and the distance of the point from that edge?

ok, here is what I’m trying to do…

(All this in 3D) I have a point P1 on triangle and I want to find D (the distance to the nearest edge), and find P2 (the point on edge) and V (the perpendicular vector to edge).

You said “ using a point on the edge” that would be P2? But how do I find P2?

*any* point on the edge - for instance one of the triangle
vertices, such as T1. So, P2 = T1 + dot(P1 - T1, E2) * E2 (here E2
should be normalized). Then you can easily calculate D and V from P1 and
P2.

No matter where my point is (if E2 is the closest edge), P2 sticks near T1. Any ideas Reedbeta?

@Alienizer

We have to normalize both operand in the dot, then mult the dot result by (p1-t1).length

That would work, but the multiply is just canceling out the normalize of (p1 - t1). It’s enough for e2 to be normalized in the expression “dot(p1 - t1, e2) * e2”. Note that the dot product doesn’t give results in [-1, 1] in this case. It gives the length of the projection of (p1 - t1) onto e2.

Are you saying that this is how it should be?…

dot( (p1-t1).length , e2 ) * normalize(e2)

as oppose to…

dot( p1-ti , e2 ) * normalize(e2)

EDIT:

dot( (p1-t1).length , e2 ) * normalize(e2) that can’t work because length is not a vector.

dot( p1-ti , e2 ) * normalize(e2) does not work.

P2 = T1 + (P1-T1).length * dot( normalize(P1-T1), normalize(E2)) * E2

here the dot gives me the cosine from which I get the length along T1 which would then be P2.

BOTH uses of e2 have to be normalized! dot(p1 - t1, normalize(e2)) * normalize(e2)

Or alternatively, to save yourself a couple of square roots, dot (p1 - t1, e2) / dot(e2, e2) * e2

oh! I thought e2 in the dot() didn’t have to be since (p1-t1) is not!

So the dot() using a non-normalized vector (p1-t1) against a direction vector (e2) is the same as the cosine * (p1-t1).length ?

@Alienizer

So the dot() using a non-normalized vector (p1-t1) against a direction vector (e2) is the same as the cosine * (p1-t1).length ?

Yes, that’s right. More generally, for any vectors u, v, it’s true that dot(u, v) = cosine(u, v) * length(u) * length(v).

- Upcoming Multiplatform Game Program...
- my new game 'squarecity' feedback w...
- Our first game - looking for feedbacks
- Network Emulation Tool
- Trouble with accessing GLSL array
- Fiction
- Game Programming Patterns: Bytecode
- Interactive WebGL Water Demo
- Skeletal Animation Tutorial with GP...
- Unreal Engine 4

Is there a way to find the perpendicular vector of a 3d triangle edge, pointing in the same direction as the triangle plane? I want to add a line on each of the 3 edges pointing outward of the triangle while staying in the same plane so the whole thing stays “flat”.

Thanks