找到路径上的坐标

时间:2021-09-30 21:27:00

My trigonometry needs a little help.

我的三角学需要一些帮助。

How would I go about calculating the point of the nearest possible intersection with a line along a rounded corner?

我如何计算沿着圆角的最近可能的交叉点的点?

Take this image:

拍下这张图片:

找到路径上的坐标

What I would like to know is, given that I know point a, and the dimensions of the rectangle, how would I find point b when the edges of the rectangle are curved?

我想知道的是,鉴于我知道点a和矩形的尺寸,当矩形边缘弯曲时,我如何找到点b?

So far, as you can see, I've only managed to calculate the nearest edge of the rectangle as if it had right-angled corners.

到目前为止,正如您所看到的,我只是设法计算矩形的最近边缘,就好像它有直角。

If it matters, I'm doing this in ActionScript 3. But example sudo-code will suffice.

如果重要,我在ActionScript 3中这样做。但是示例sudo-code就足够了。

3 个解决方案

#1


Calculate the vector from the midpoint M of the corner to A:

计算从角点的中点M到A的向量:

v_x = a_x - m_x

v_x = a_x - m_x

v_y = a_y - m_y

v_y = a_y - m_y

then go radius of the corner r times towards A to get to the intersection point I

然后转向角落的半径r朝A方向到达交叉点I.

i_x = m_x + r*v_x

i_x = m_x + r * v_x

i_y = m_y + r*v_y

i_y = m_y + r * v_y

This obviously only works if the nearest intersection is on the rounded corner. Just calculate the other intersections with the edges, too, and then check which has the nearest distance to A.

这显然只有最近的交叉点在圆角上才有效。只计算边缘的其他交叉点,然后检查哪个交叉点与A的距离最近。

#2


You need to know the radius R of the circle that generates the round corner and the coordinates (Xr,Yr) of the point where the two sides of a non rounded rectangle cross each other.

您需要知道生成圆角的圆的​​半径R以及非圆角矩形的两边相互交叉的点的坐标(Xr,Yr)。

Then the coordinates for the center of the circle that generates the round corner are (Xc, Yc) = (Xr-R, Yr-R)

那么生成圆角的圆心的坐标是(Xc,Yc)=(Xr-R,Yr-R)

From here, it's a matter of solving the equation of the cross point between the segment line defined by point A=(Xa, Ya) and point (Xc, Yc), whose parametric equation is:

从这里开始,需要解决由点A =(Xa,Ya)和点(Xc,Yc)定义的分段线之间的交叉点方程,其参数方程为:

x = Xa + p*(Xc-Xa)
y = Ya + p*(Yc-Ya)

and the circle whose equation is

和等式的圆

(x-Xc)^2 + (y-Yc)^2 = R^2

Substitute values for x and y from the parametric euation of the line in the equation of the circle, and you will have an equation with only one unkown: p. Solve the equation, and if there are more than one solution, choose the one that is in the range [0,1]. Substitute the found value of p in the parametric equation of the line to get the point of intersection.

从圆的方程中的线的参数化euation中替换x和y的值,你将得到一个只有一个未知的方程式:p。求解方程,如果有多个解,请选择[0,1]范围内的解。在线的参数方程中替换p的找到值以得到交点。

Graphically:

找到路径上的坐标

#3


If you know the radius and center of the corner as R and C=(Xc, Yc), then the nearest point on the corner to the given point A=(Xa, Ya) is the intersection point of the corner and the line defined by the given point and the center. This point can be directly expressed as

如果你知道拐角的半径和中心为R和C =(Xc,Yc),那么拐角到给定点A =(Xa,Ya)的最近点是拐角和定义的直线的交点由给定点和中心。这一点可以直接表示为

X = Xc + R*(Xa-Xc)/|AC|
Y = Yc + R*(Ya-Yc)/|AC|

X = Xc + R *(Xa-Xc)/ | AC | Y = Yc + R *(Ya-Yc)/ | AC |

where |AC| = Sqrt((Xa-Xc)^2 + (Ya-Yc)^2)

哪里| AC | = Sqrt((Xa-Xc)^ 2 +(Ya-Yc)^ 2)

#1


Calculate the vector from the midpoint M of the corner to A:

计算从角点的中点M到A的向量:

v_x = a_x - m_x

v_x = a_x - m_x

v_y = a_y - m_y

v_y = a_y - m_y

then go radius of the corner r times towards A to get to the intersection point I

然后转向角落的半径r朝A方向到达交叉点I.

i_x = m_x + r*v_x

i_x = m_x + r * v_x

i_y = m_y + r*v_y

i_y = m_y + r * v_y

This obviously only works if the nearest intersection is on the rounded corner. Just calculate the other intersections with the edges, too, and then check which has the nearest distance to A.

这显然只有最近的交叉点在圆角上才有效。只计算边缘的其他交叉点,然后检查哪个交叉点与A的距离最近。

#2


You need to know the radius R of the circle that generates the round corner and the coordinates (Xr,Yr) of the point where the two sides of a non rounded rectangle cross each other.

您需要知道生成圆角的圆的​​半径R以及非圆角矩形的两边相互交叉的点的坐标(Xr,Yr)。

Then the coordinates for the center of the circle that generates the round corner are (Xc, Yc) = (Xr-R, Yr-R)

那么生成圆角的圆心的坐标是(Xc,Yc)=(Xr-R,Yr-R)

From here, it's a matter of solving the equation of the cross point between the segment line defined by point A=(Xa, Ya) and point (Xc, Yc), whose parametric equation is:

从这里开始,需要解决由点A =(Xa,Ya)和点(Xc,Yc)定义的分段线之间的交叉点方程,其参数方程为:

x = Xa + p*(Xc-Xa)
y = Ya + p*(Yc-Ya)

and the circle whose equation is

和等式的圆

(x-Xc)^2 + (y-Yc)^2 = R^2

Substitute values for x and y from the parametric euation of the line in the equation of the circle, and you will have an equation with only one unkown: p. Solve the equation, and if there are more than one solution, choose the one that is in the range [0,1]. Substitute the found value of p in the parametric equation of the line to get the point of intersection.

从圆的方程中的线的参数化euation中替换x和y的值,你将得到一个只有一个未知的方程式:p。求解方程,如果有多个解,请选择[0,1]范围内的解。在线的参数方程中替换p的找到值以得到交点。

Graphically:

找到路径上的坐标

#3


If you know the radius and center of the corner as R and C=(Xc, Yc), then the nearest point on the corner to the given point A=(Xa, Ya) is the intersection point of the corner and the line defined by the given point and the center. This point can be directly expressed as

如果你知道拐角的半径和中心为R和C =(Xc,Yc),那么拐角到给定点A =(Xa,Ya)的最近点是拐角和定义的直线的交点由给定点和中心。这一点可以直接表示为

X = Xc + R*(Xa-Xc)/|AC|
Y = Yc + R*(Ya-Yc)/|AC|

X = Xc + R *(Xa-Xc)/ | AC | Y = Yc + R *(Ya-Yc)/ | AC |

where |AC| = Sqrt((Xa-Xc)^2 + (Ya-Yc)^2)

哪里| AC | = Sqrt((Xa-Xc)^ 2 +(Ya-Yc)^ 2)