如何根据角度和不同的边长计算X和Y坐标

huangapple go评论80阅读模式
英文:

How to calculate X and Y coordinates given an angle and varying side lengths

问题

我正在开发一个使用Google Maps JavaScript API的应用程序,允许用户绘制多个折线路径,计算角度,然后尝试弯曲这些角度,模拟车辆的转弯半径。为了做到这一点,我需要知道弯曲的起始点和终点。问题在于这些角度可以在地图上的任何方向,我在寻找适当的方法来计算这些点的(X,Y)坐标方面遇到了困难...我可以计算大小,但由于不同的方向,不确定如何将其转换为一组笛卡尔坐标。以下是几何结构的概述:

如何根据角度和不同的边长计算X和Y坐标

最终,我有点A、B和C,角度a以及圆的半径。在这种情况下,如何计算点P1、P2和(未标记的)贝塞尔曲线的绿色参考点的笛卡尔坐标?这些点不需要具体,只需大致指导曲线。

英文:

I am building a Google Maps Javascript API application that allows the user to draw a path of multiple polylines, calculates the angles, then attempts to curve the angles, simulating a vehicle turning radius. In order to do this, I need the point the curve starts and stops at. The problem is that these angles can be in any assortment of directions on a map, and I am struggling to find the appropriate way to calculate the (X,Y) coordinates of these points... I can calculate the magnitude, but due to the varying orientation, am not sure how to get it back to a set of cartesian coordinates. Here is an outline of the geometry:

如何根据角度和不同的边长计算X和Y坐标

Ultimately, I have points A, B, and C, angle a, and the radius of the circle. Given that, how can I calculate points P1, P2, and (not labeled) the green reference points for the bezier curve in terms of cartesian coordinates? These points do not have to be specific, just in the general area to guide the curve.

答案1

得分: 0

Vectors BA and BC are defined as follows:

BA.x = A.x - B.x
BA.y = A.y - B.y, etc.

Unit vectors are calculated as:

len(BA) = sqrt(BA.x * BA.x + BA.y * BA.y)
uBA = BA / len(BA) (uBA.x = BA.x / len(BA), etc)
uBC = BC / len(BC)

The cosine of the angle between vectors is obtained as:

cs = cos(fullangle) = dot(uBA, uBC) = uBA.x * uBC.x + uBA.y * uBC.y

The tangent of half-angle is determined by:

tn = sqrt((1 - cs) / (1 + cs))

To calculate points that provide a normal distance R from the bisector to lines, use these formulas:

P1 = B + uBA * R / tn (P1.x = B.x + uBA.x * R / tn, etc.)
P2 = B + uBC * R / tn

For smooth conjugation of a Bezier curve and lines, the control points on lines are defined as:

C1 = P1 - uBA * R * coeff
C2 = P2 - uBC * R * coeff

Where the coefficient should be adjusted for a "smart curve" look, typically in the range 0.3 to 1. A common value is:

coeff = 0.552

This value for right-angled lines results in an almost perfect circle arc. In general, the coefficient can be approximated as:

coeff = 4/3 * tg(angle/4)

Please note that the code and formulas provided here are not translated, as requested.

英文:

Make vectors BA and

BA.x = A.x-B.x
BA.y = A.y-B.y etc

Make unit vectors

len(BA) = sqrt(BA.x*BA.x+BA.y*BA.y)
uBA = BA / len(BA)       (uBA.x = BA.x/len(BA) etc)
uBC = BC / len(BC)

Get cosine of angle between vectors

cs = cos(fullangle) = dot(uBA, uBC) = uBA.x*uBC.x + uBA.y*ubC.y

Get tangent of half-angle

tn = sqrt((1-cs)/(1+cs))

Calculate points to provide normal distance R from bisector to lines

P1 = B + uBA * R / tn   (P1.x = B.x + uBA.x * R / tn   etc)
P2 = B + uBC * R / tn

Note that smooth conjugation of Bezier curve and lines requires control points on lines, so

C1 = P1 - uBA * R * coeff
C2 = P2 - uBC * R * coeff

Where coefficient should be adapted for "smart curve" look, perhaps in range 0.3..1.

coeff=0.552 

for right-angled lines gives almost perfect circle arc.

In general

coeff = 4/3*tg(angle/4) 

is nice approximantion

huangapple
  • 本文由 发表于 2023年4月11日 07:47:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/75981504.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定