# Height at point in triangle

**URL:** <https://forum.kirupa.com/t/height-at-point-in-triangle/322189>\
**Category:** flash\
**Created:** [May 13, 2011, 1:20pm UTC](https://forum.kirupa.com/t/height-at-point-in-triangle/322189 "2011-05-13T13:20:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fikontrollet](https://avatars.discourse-cdn.com/v4/letter/f/35a633/32.png) [@fikontrollet](https://forum.kirupa.com/u/fikontrollet)\
**Post date:** [May 13, 2011, 1:20pm UTC](https://forum.kirupa.com/t/height-at-point-in-triangle/322189/1 "2011-05-13T13:20:39Z")

</div>

[LEFT]Hey guys  
Using \*[http://gpwiki.org/index.php/MathGem:Height\_of\_a\_Point\_in\_a\_Triangle](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;\*

```php

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