Perpendicular line at 3d triangle edge

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Mar 30, 2013 at 18:01

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

17 Replies

Please log in or register to post a reply.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Mar 30, 2013 at 18:02

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

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Mar 30, 2013 at 18:23

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?

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Mar 30, 2013 at 18:32

You can find the distance of a point from an edge using a point on the edge (a vertex) and a unit vector that points along the edge. If P is the point, V is the vertex and E is the normalized edge vector, then you can calculate the perpendicular vector from the edge to the point as (P - V) - dot(P - V, E) * E. Then the distance to the point is just the length of that vector. Do it for all three edges and take the minimum.

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Mar 30, 2013 at 18:52

Thanks Reedbeta :)

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Mar 30, 2013 at 19:16

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

2mgwnk8.jpg

(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?

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Mar 30, 2013 at 19:28

I meant using 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.

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Mar 30, 2013 at 19:37

oh I get it! Thanks again Reedbeta, much appreciated.

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Mar 30, 2013 at 22:21

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

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Mar 31, 2013 at 01:10

It’s not working Reedbeta, the dot() gives numbers way above the range! If I sqrt the dot() then I get values within range, but it’s offset so I don’t think it’s correct.

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Mar 31, 2013 at 02:00

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

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Mar 31, 2013 at 19:10

@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.

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Mar 31, 2013 at 20:47

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.

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Mar 31, 2013 at 20:54

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.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Mar 31, 2013 at 23:48

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

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Apr 01, 2013 at 00:17

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 ?

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Apr 01, 2013 at 01:25

@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).

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Apr 01, 2013 at 01:28

Thanks Reedbeta.