translate Python in to Unity C# - Maths OR how to find Shortest distance between two skew lines in 3D space -


i think it'll enough if understand what

np.linalg.norm(a) np.linalg.det([t, _a, cross]) np.cross(_a, _b) 

does

python code founded here 6. answer @fnord

i looking @ doc, couldn't understand thing it's worst in msdn doc

edit:

i deleted code assumptions totally incorrect.

even if original question wasn't answered original problem solved.

problem:

how find 2 closest points between 2 skew lines in 3d

this gr8 tutorial could've helped me if i'd understood how learn programmatically t , s is.

you don't need rewrite these methods, there equivalent methods built-in.

for example, distance between 2 3-dimensional vectors, can use vector3.distance (unity entry)

float distance = vector3.distance(somevector, anothervector); 

if want find 2 closest points, should able accomplish using other vector methods well.

here example of how use methods find closest points on 2 difference lines (taken unity wiki). still uses determinants calculate this. explanation of why works, need understand basic linear algebra vectors.

//two non-parallel lines may or may not touch each other have point on each line closest //to each other. function finds 2 points. if lines not parallel, function  //outputs true, otherwise false. public static bool closestpointsontwolines(out vector3 closestpointline1, out vector3 closestpointline2, vector3 linepoint1, vector3 linevec1, vector3 linepoint2, vector3 linevec2){      closestpointline1 = vector3.zero;     closestpointline2 = vector3.zero;      float = vector3.dot(linevec1, linevec1);     float b = vector3.dot(linevec1, linevec2);     float e = vector3.dot(linevec2, linevec2);      float d = a*e - b*b;      //lines not parallel     if(d != 0.0f){          vector3 r = linepoint1 - linepoint2;         float c = vector3.dot(linevec1, r);         float f = vector3.dot(linevec2, r);          float s = (b*f - c*e) / d;         float t = (a*f - c*b) / d;          closestpointline1 = linepoint1 + linevec1 * s;         closestpointline2 = linepoint2 + linevec2 * t;          return true;     }      else{         return false;     } } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -