Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: Distance from 3D point to line segments Date: Sat, 20 Oct 2012 09:34:08 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 26 Message-ID: <k5tr6g$ptu$1@newscl01ah.mathworks.com> References: <k5shn7$c08$1@newscl01ah.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: www-01-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: newscl01ah.mathworks.com 1350725648 26558 172.30.248.46 (20 Oct 2012 09:34:08 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Sat, 20 Oct 2012 09:34:08 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1187260 Xref: news.mathworks.com comp.soft-sys.matlab:781030 "Sean" wrote in message <k5shn7$c08$1@newscl01ah.mathworks.com>... > ....... I am struggling with creating the arcs/curves in 3D. I have the 2 end points and the radius. I then need to compare distance of a 3D point to this 3D curve... - - - - - - - - - - - If your curves are true circular arcs (as hinted at by your use of the term 'radius') then there is an explicit formula for the closest distance to an arc from any given point in 3D. We assume here the arc angle is less than pi radians. (In the image yours look about pi/2 radians.) Let the center of an arc be point C, and the two arc endpoints be A and B. Let R = norm(A-C) = norm(B-C) be the arc's radius. Then compute: u = cross(A-C,B-C); u = u/norm(u); % Make u a unit vector v = cross(u,A-C); w = cross(B-C,u); With any given point P first compute PC = P-C; Then if the inequalities dot(v,PC) >= 0 and dot(w,PC) >= 0 are both true, the minimum distance to a point on the arc from P is: d = sqrt(dot(PC,PC)+R^2-2*R*norm(cross(PC,u))); % Cosine law of triangles If the two inequalities are not both true, then either one of the two endpoints is the closest point or else some other line or arc segment is closest. If the arcs are all tangent to adjacent line segments as in your image, it would be the latter. Roger Stafford