0

I have two problem first how to calculate the minimum distance between two lines. For details I am attaching an image here.

enter image description here

In the image describe the line with start and end point. I already have start and end point for both lines but I am not getting any idea how to calculate the minimum distance between two lines.

Another problem is that how to calculate the minimum distance between two arc. I am attaching another image here

enter image description here

For arc I have the start, end and center point also I have the start and end angle.

This link has lot more things - Shortest distance between a point and a line segment

I also got help from above link.

enter image description here

This is the another issue what I am facing now. In this scenario how to calculate minimum distance between two arc?

Any idea how solve this two issue?

Community
  • 1
  • 1
Shiladittya Chakraborty
  • 4,270
  • 8
  • 45
  • 94

2 Answers2

2

Let the two segments be AB and CD. Their parametric equations can be written

P = A + u AB, Q = C + v CD, with u, v in [0, 1].

You want to minimize the (squared) distance

PQ² = (CA + u AB - v CD)², under the given constraints,

and you can cancel the first derivatives with

(CA + u AB - v CD).AB = 0
(CA + u AB - v CD).CD = 0

After resolution of the 2x2 system you get a pair (u, v). If both variables fall in [0,1], there is an intersection and the distance is 0.

Otherwise, clamp u and/or v to the relevant bound of range [0, 1] and compute the corresponding distance.

If one variable was clamped, the distance was between an endpoint and a segment; if two were clamped, it's between two endpoints.


A similar approach can be adopted for the arcs (using trigonometric functions), and lead to an optimization problem under linear constraints. Less easy to handle as the objective function is non-linear, though.


We can also proceed as follows:

  • find the points that make the shortest distance between the whole circles. There are two cases:

    • the circles intersect, at two places

    • the circles do not intersect; the shortest distance is between the intersection points of the two circles and the center line.

  • then check if these points do belong to the arcs by angle comparison. If yes, you are done (the distance is either 0 or the distance between the intersections).

  • otherwise, consider the endpoints of an arc against the other circle. The closest point is the intersection of the circle with the line through the point and the center. If the intersection belongs to the arc, keep the distance between the point and the intersection. Repeat this for all four combinations endpoint/arc and keep the closest pair.

  • If no valid pair was found, keep the shortest endpoint/endpoint distance.

The picture shows the distances that can be considered. In green, endpoint/circle; in red, endpoint/endpoint. In this case, the circle/circle distance is zero as they intersect. A distance can be considered if it joins two points inside the arcs.

enter image description here

-1

Distance between two intersecting lines is 0

Otherwise, what you want is to calculate the endpoint of one of the line to the other one. If you want to calculate the distance between a point and a line :

It is the length of the line segment which joins the point to the line and is perpendicular to the line.

For arcs I think arcs are part of circles, distance between them is the distance between their center points and minus their radiuses.

Probably you can find more here: Calculate the minimum distance between two given circular arcs

Example example

Community
  • 1
  • 1
phuwin
  • 3,130
  • 4
  • 26
  • 49