给定固定的角度,宽度和矢状面,如何计算椭圆的水平和垂直半径?
我想绘制一个具有给定的弧宽,高度(Sagitta)且为椭圆的给定角度的椭圆弧。在下图中,虚线为黑色和黄色。为此,我需要知道椭圆的2个半径。
对于一个圆,可以很容易地计算出它的1个半径,并给出任意两个角度,弧度或宽度值。请参见下面的代码段。如何使该功能适用于椭圆形?在该图中,角度可以说是从-60到60对称,使角度为120。这是我真正需要的情况,即弧在垂直轴或水平轴的两侧都反射自身。如果角度是120,从80开始到200,那么就没有真正的弧线,只有弧的最高点和一个紧密的边界框,如果有人也有解决方案,它将很难解决。成为奢侈品。
var arcCalc = function(r, w, a, s) {
// to allow for object usage
if (r instanceof Object) {
w = r.w || r.width;
a = r.a || r.angle;
s = r.s || r.sagitta;
r = r.r || r.radius;
}
w = this.toPts(w);
s = this.toPts(s);
r = this.toPts(r);
var sin, cos, twoKnown;
sin = Math.sin;
cos = Math.cos;
// if we know any two arguments then we can work out the other ones
// if not we can't
twoKnown = +!r + +!w + +!a + +!s < 3;
// At this point of time we are trying to avoid throwing errors
// so for now just throw back the garbage we received
if (!twoKnown)
return {
radius: r,
width: w,
angle: a,
sagitta: s,
r: r,
w: w,
a: a,
s: s
};
if (a) {
a *= Math.PI / 180;
}
if (!r) {
if (!s) {
r = w / (2 * sin(a / 2));
} else if (!a) {
r = (s * s + 0.5 * w * (0.5 * w)) / (2 * s);
} else {
r = s / (1 - cos(a / 2));
}
}
// at this point we know we have r
if (!w) {
if (!s) {
w = 2 * r * sin(a / 2);
} else {
w = 2 * Math.sqrt(s * (2 * r - s));
}
}
// at this point we know we have r and w
if (!a) {
if (!s) {
// We added the round because
// w / (2*r) could come to 1.00000000001
// and then NaN would be produced
a = 2 * Math.asin(this.round(w / (2 * r)));
} else {
a = 2 * Math.acos(this.round(1 - s / r));
}
}
if (!s) {
s = r - r * cos(a / 2);
}
a *= 180 / Math.PI;
return {
radius: r,
width: w,
angle: a,
sagitta: s,
r: r,
w: w,
a: a,
s: s
};
};
给出角度α,宽度和弧度。圆的半径r
可以从alpha计算,而宽度可以从正弦公式计算。同样,x - sagitta
从余弦公式得出。
要找到y
,我们将图形以y/x
的比例缩放到x方向。这会将椭圆转换为半径为y
的圆。它将[x-sagitta, width/2]
上的点转换为[(x-sagitta)*y/x, width/2]
。该变换点必须位于半径为y
的圆上。我们在y
中得到一个二次方程:
((x-sagitta)*y/x)^2, (width/2)^2 = y^2
。
其积极的解决方法是
y = width * x * sqrt(1 / (sagitta * (2 * x - sagitta))) / 2
。
恢复,得出(r是圆的半径,x和y是椭圆的轴):
r = width / 2 / sin(alpha / 2)
x = r * cos(alpha / 2) + sagitta
y = width * x * sqrt(1 / (sagitta * (2 * x - sagitta))) / 2
使用Python和matplotlib的检查:
from matplotlib import pyplot as plt
from matplotlib.patches import Ellipse
from math import sqrt, sin, cos, atan, pi
sagitta = 15
alpha = 120 * pi / 180
width = 100
r = width / 2 / sin(alpha / 2)
x = r * cos(alpha / 2) + sagitta
y = width * x * sqrt(1 / (sagitta * (2 * x - sagitta))) / 2
print(x, y)
print(r)
ax = plt.gca()
ax.plot([r * cos(alpha / 2), 0, r * cos(alpha / 2)], [- r * sin(alpha / 2), 0, r * sin(alpha / 2)], ls='-',
color='crimson')
ellipse = Ellipse((0, 0), 2 * x, 2 * y, color='purple', linewidth=1, fill=False, ls='-')
circle = Ellipse((0, 0), 2 * r, 2 * r, color='tomato', linewidth=1, fill=False, ls='-.')
lim = max(x, y) * 1.05
ax.set_xlim(-lim, lim)
ax.set_ylim(-lim, lim)
ax.axhline(0, color='silver')
ax.axvline(0, color='silver')
ax.plot([x-sagitta, x-sagitta], [width/2, -width/2], color='limegreen', ls='--')
ax.plot([x-sagitta, x], [0, 0], color='brown', ls='--')
ax.add_patch(ellipse)
ax.add_patch(circle)
ax.text(x-sagitta, width/2, ' [x-s, w/2]')
ax.set_aspect(1)
plt.show()