javascript - Calculate vector sign(positive/negative) -


i'm trying calculate normal vector 3 points, getting 2 vectors them , calculate normal. need know if normal positive or negative. pls :)

the normal vector, can has direction, , value (or magnitude or length), no sign.

the direction of normal depends on order, pass values.

i assume asking culling, wether vector front or @ face? can calculate dot-product of vector , normal.

result > 0 point in same direction,
result < 0 point in opposite directions

function pt(x,y,z){ return { x: +x||0, y: +y||0, z: +z||0 } }  function dot(a,b){ return b.x*a.x + b.y*a.y + b.z-a.z }  function delta(a,b){ return pt(b.x-a.x, b.y-a.y, b.z-a.z) } function cross(a,b){     return pt( a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x ) }  var face = [     pt(0,0,0),      pt(1,0,0),     pt(0,1,0) ];  var vector; var normal = cross(     delta(face[0], face[1]),     delta(face[1], face[2]) );  console.log('normal', normal);  console.log(vector = pt(0, 0, 10), dot(normal,vector)); console.log(vector = pt(0, 0, -1), dot(normal,vector));  //pretty flat angle still enough determine direction console.log(vector = pt(1, 1, .00005), dot(normal,vector)); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -