[LEFT]Hey guys
Using *http://gpwiki.org/index.php/MathGem:Height_of_a_Point_in_a_Triangle *i tried to write a method that returns the properties of a given point in a triangle, unfortunately, it’s not returning the proper values.
Does it matter what vertice in the triangle i use?
The example below returns -200, which obviously is totally wrong.
Does anyone spot what might be wrong?
Instead of X,Y,Z : p, q, r = 0, 2, 1 (in this case : x, z, y)
Point : P = 100,0,-100
Normal : N = 50,33.333333333333336,-50
Triangle Vertices : T = -150,100,-150,150,0,150,150,0,-150
*For simplicity i used the first triangle (3 first values in the triangles vertices) *
My method better explained:
y = ((N.x(P.x-T1.x) + N.z*(P.z-T1.z))/-N.y)+T1.y;*
// _v -- 0:X | 1:Y | 2:Z
public static function generateHeightTriangle(mesh:Mesh3D, point:Vector.<Number>, _v:int = 1):Number{
var P:Vector.<Number> = point;
var V:Number = 0;
var N:Vector.<Number> = Vec3D.generateFaceNormalPosition(mesh);
var T:Vector.<Number> = Vec3D.generateTriangleFromMesh(mesh);
var _p:int = (_v+2)%3; // = 0
var _q:int = (_v+1)%3; // = 2
var _r:int = _v%3; // Same var as output
if(N[_r] == 0) N[_r] = 0.01; // Dont ever try to devide by Zero, Ever!
V = ((N[_p]*(P[_p]-T[_p]) + N[_q]*(P[_q]-T[_q]))/-N[_r])+T[_r];
return V;
}
[/LEFT]