Re: [Algorithms] Nearest point on plane for 2D IK
Brought to you by:
vexxed72
From: Dave E. <eb...@ma...> - 2000-08-30 02:22:13
|
From: "David Kornmann" <da...@ik...> > - Take the plane defined with the ray and the center of the sphere. > - Rotate the ray around its origin and along the plane until it is tangent to > the sphere. > - Compute the tangetial point (easy). Let C be the center of the sphere and let R be its radius. Let the ray have origin P and direction vector D. Assume the ray does not pass through C. The plane containing C and the ray has normal N = Cross(D,C-P). The plane itself is Dot(N,X-P) = 0. Let L = Length(C-P). The point you are looking for can be viewed as a point of intersection of the sphere |X-C|^2 = R^2, the sphere |X-P|^2 = L^2, and the plane Dot(N,X-P) = 0. This gives you three equations (two quadratic, one linear) in three unknowns. Alternatively you can think of intersecting each of the spheres with the plane. Within the plane you need to find the intersection of two circles. You can reduce the two quadratics to one. Subtract the sphere equations to get 2*Dot(P-C,X) + |C|^2 - |P|^2 = R^2 - L^2. Do the algebra to set up the three equations as p0 = (x-c0)^2 + (y-c1)^2 + (z-c2)^2 - R^2 = 0 p1 = a0*x+a1*y+a2*z+a3 p2 = b0*x+b1*y+b2*z+b3 res0 = Resultant[p0,p1,z] = d20*x^2+d11*x*y+d02*y^2+d10*x+d01*y+d00 where d00 = a3^2+2*a2*a3*c2+a2^2*(c0^2+c1^2+c2^2-R^2) d10 = 2*(a0*a3-a2^2*c0+a0*a2*c2) d01 = 2*(a1*a3-a2^2*c1+a1*a2*c2) d11 = 2*a0*a2 d20 = a0^2+a2^2 d02 = a1^2+a2^2 res1 = Resultant[p1,p2,z] = e0*x+e1*y+e2 where e0 = a2*b0-a0*b2 e1 = a2*b1-a1*b2 e2 = a2*b3-a3*b2 res2 = Resultant[res0,res1,y] = f2*x^2 + f1*x + f0 where f0 = d00*e1^2 - d01*e1*e2 + d02*e2^2 f1 = d10*e1^2+2*d02*e0*e2-d01*e0*e1-d11*e1*e2 f2 = d02*e0^2-d11*e0*e1+d20*e1^2 Solve res2 = 0 for up to 2 values of x. For each, solve res1 = 0 for y. For each pair (x,y) from this construction, solve p1 = 0 for z. You get up to two points (x,y,z). The one that is in the wedge formed by the ray P+t*D and P+t*(C-P) is the solution you want. -- Dave Eberly eb...@ma... http://www.magic-software.com |