Witam szukam rozwiązania równania najmniejszej odległości między dwoma odcinkami trójwymiarowymi jeden odcinek to punkty A(xa,ya,za)B(xb,yb,zb) i drugi odcinek C(xc,yc,zc) D(xd,yd,zd). Znalazlem jakiegos matematyka co mi powiedzial ze obliczyc to mozna na podstawie wysokosci rownolegloscianu, podal mi nawet wzor ale ja przez przypadek usunalem tego mailai i nawet nie mam z nim kontaktu wiec zwracam sie do ludzi, ktorzy ogarniaja ten temat zeby mi pomogli
0
0
znalazlem taki kod tylko na koncu return jest funkcja return norm(db); nie wiem co to jest norm ale to robi z wektora float
float dist3D_Segment_to_Segment( t3dpoint S1p0, t3dpoint S1p1, t3dpoint S2p0, t3dpoint S2p1)
{
t3dpoint u = vectorAB(S1p0,S1p1);// S1.P1 - S1.P0; vector AB equals to B - A
t3dpoint v = vectorAB(S1p0,S1p1);//S2.P1 - S2.P0;
t3dpoint w = vectorAB(S2p0,S1p0);//S1.P0 - S2.P0;
float a = Dot(u,u); // always >= 0
float b = Dot(u,v);
float c = Dot(v,v); // always >= 0
float d = Dot(u,w);
float e = Dot(v,w);
float D = a*c - b*b; // always >= 0
float sc, sN, sD = D; // sc = sN / sD, default sD = D >= 0
float tc, tN, tD = D; // tc = tN / tD, default tD = D >= 0
// compute the line parameters of the two closest points
if (D < SPECIAL_FEAUTRE) { // the lines are almost parallel
sN = 0.0; // force using point P0 on segment S1
sD = 1.0; // to prevent possible division by 0.0 later
tN = e;
tD = c;
}
else { // get the closest points on the infinite lines
sN = (b*e - c*d);
tN = (a*e - b*d);
if (sN < 0.0) { // sc < 0 => the s=0 edge is visible
sN = 0.0;
tN = e;
tD = c;
}
else if (sN > sD) { // sc > 1 => the s=1 edge is visible
sN = sD;
tN = e + b;
tD = c;
}
}
if (tN < 0.0) { // tc < 0 => the t=0 edge is visible
tN = 0.0;
// recompute sc for this edge
if (-d < 0.0)
sN = 0.0;
else if (-d > a)
sN = sD;
else {
sN = -d;
sD = a;
}
}
else if (tN > tD) { // tc > 1 => the t=1 edge is visible
tN = tD;
// recompute sc for this edge
if ((-d + b) < 0.0)
sN = 0;
else if ((-d + b) > a)
sN = sD;
else {
sN = (-d + b);
sD = a;
}
}
// finally do the division to get sc and tc
sc = (abs(sN) < SPECIAL_FEAUTRE ? 0.0 : sN / sD);
tc = (abs(tN) < SPECIAL_FEAUTRE ? 0.0 : tN / tD);
// get the difference of the two closest points
t3dpoint dP = vectors_add( w, vectors_substract_v1minusv2(vector_multiple(u,sc),vector_multiple(v,tc))); // = S1(sc) - S2(tc)
// return Normalize(dP); // return the closest distance
}
0
http://softsurfer.com/Archive/algorithm_0106/algorithm_0106.htm
#define dot(u,v) ((u).x * (v).x + (u).y * (v).y + (u).z * (v).z)
#define norm(v) sqrt(dot(v,v)) // norm = length of vector
Zapomniałeś to wkleić ;) Teraz już powinieneś widzieć co się dzieje.
0
no wlasnie chodzilo mi o ta normalizacje :)