Calculate intersect point between arc and line

2019-02-18 21:03发布

I want to calculate the intersect point between arc and line. I have all the data for line and arc.

For line : start and and end point.
For arc : start/end point, start/end angle, radius and center point.

I have attach here one image. In this below image I have draw one arc and line where line intersect the arc.

So now I want to find the intersect point. Please give me some algorithm or idea or if any available code.

enter image description here

标签: java geometry
2条回答
老娘就宠你
2楼-- · 2019-02-18 21:27

A point on the arc has coordinates

R.cos(t) + Xc
R.sin(t) + Yc

Using the implicit form of the line equation (either given or obtained from two given points),

A.X + B.Y + C = 0

then

A.R.cos(t) + B.R.sin(t) + A.Xc + B.Yc + C = 0

To solve this trigonometric equation, first divide both members by R.√A²+B², giving

c.cos(t) + s.sin(t) = d

which can be rewritten, with tan(p) = s/c and d = cos(q):

cos(t-p) = cos(q)

then

t = p +/- q = arctan(B/A) +/- arccos(-(A.Xc + B.Yc + C)/R.√A²+B²)

Eventually, you will need to check if these values of t fall in the range (start, end), modulo 2π.

查看更多
仙女界的扛把子
3楼-- · 2019-02-18 21:38

Let's define an arc and a line:

Arc:

  • xa=X-coordinate
  • ya=Y-coordinate
  • a1=starting angle (smaller angle)
  • a2=ending angle (greater angle)
  • r=radius

Line:

  • x1=first X-coordinate
  • x2=second X-coordinate
  • y1=first Y-coordinate
  • y1=second Y-coordinate

From that you can calculate:

  • dx=x2-x1
  • dy=y2-y1
  • al=arctan(dy/dx) (Angle of the line)

The arc and the line won't intersect when al < a1 or al > a2 or, in other words, the angle of the line isn't between the angles of the arc. The equations for an intersection are as follows:

  • xa+rcos(al)=x1+cdx
  • ya+rsin(al)=y1+cdy

where c (0 < c <= 1)is the variable we're looking for. Specifically:

  • (xa+r * cos(al)-x1)/dx=c
  • (ya+r * sin(al)-y1)/dy=c

The intersection point is therefore at (x1+c * dx),(y1+c * dy)

This algorithm only works when the arc and the line have one single intersection. If the line goes through the arc two times then it won't register any intersection.

查看更多
登录 后发表回答