Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Distance from 3D point to line segments

Subject: Distance from 3D point to line segments

From: Sean

Date: 19 Oct, 2012 21:46:15

Message: 1 of 3

I have a set of 2000 X,Y,Z data points creating a rectangle with rounded corners.

Here is a plot of my data:
http://i.imgur.com/TYtPJ.jpg

I need to verify that each x,y,z point is within a certain distance from a calculated path of the same shape. I plan on recreating this plot with calculated points, 4 line segments and 4 curves, and then comparing the distance of each point in my dataset to the appropriate segment that I calculate.

I am using the following for finding distance between a point and line, 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... Any help would be greatly appreciated.


%loop comparing distance of every found point to calculated line with end points P1_1 and P1_2

for i=min:max
point=[x(i),y(i),z(i)]
  error(i) = norm(cross(P1_2-P1_1,point-P1_1))/norm(P1_2-P1_1)
end

Subject: Distance from 3D point to line segments

From: Bruno Luong

Date: 20 Oct, 2012 07:53:11

Message: 2 of 3

"Sean" wrote in message <k5shn7$c08$1@newscl01ah.mathworks.com>...
> I have a set of 2000 X,Y,Z data points creating a rectangle with rounded corners.
>
> Here is a plot of my data:
> http://i.imgur.com/TYtPJ.jpg
>
> I need to verify that each x,y,z point is within a certain distance from a calculated path of the same shape. I plan on recreating this plot with calculated points, 4 line segments and 4 curves, and then comparing the distance of each point in my dataset to the appropriate segment that I calculate.
>
> I am using the following for finding distance between a point and line, 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... Any help would be greatly appreciated.

Find a distance d from a point P to a curve C(t) is a 1D minimization problem under-constraints.

tmin argmin f(t) := | C(t)- P |^2
with a constraint t in [0,1].
d = f(tmin).

Write down the Euler-Lagrange for unconstrained problem, that allows tp solve to "te", check if te in [0,1].

- If yes take tmin = argmin f(t) i in { 0, 1, te }.
- If no take tmin = argmin f(t) i in { 0, 1 }.

Apply this for C(t) = quarter circle, or segment line.

Bruno

Subject: Distance from 3D point to line segments

From: Roger Stafford

Date: 20 Oct, 2012 09:34:08

Message: 3 of 3

"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

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us