]]>Thanks Reedbeta.

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

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

]]>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

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

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

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

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

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

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

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

]]>I meant using

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

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

]]>Thanks Reedbeta

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

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

]]>Try taking the cross product of the triangle's normal vector and the edge vector.

]]>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