簡體   English   中英

給定一個固定的角​​度、寬度和矢狀面,我們如何計算橢圓的水平半徑和垂直半徑?

[英]Given a fixed Angle, Width & Sagitta how can we calculate the horizontal and vertical radiuses of an ellipse?

給定一個固定的角​​度、寬度和矢狀面,我們如何計算橢圓的水平半徑和垂直半徑?

我想繪制一個橢圓弧,它具有給定的弧寬、高度(Sagitta)並且是給定的橢圓角度。
在下圖中,虛線的黑色和黃色弧線。 為此,我需要知道橢圓的 2 個半徑。

對於一個圓,可以很容易地計算出它的 1 個半徑,給出角度、矢狀面或寬度的任意 2 個值。
請參閱下面的片段。
如何使函數適用於橢圓? 在圖表中,角度可以說是從 -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 ,我們將繪圖縮放到 x 方向,系數為y/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

前提是2*x > sagitta 這減少到cos(alpha/2) > 0alpha < 180° 當然,矢狀面、寬度和 alpha 的極端組合會導致極度拉伸的橢圓。

繼續,這給出(r 是圓的半徑,x 和 y 是橢圓的軸):

r = width / 2 / sin(alpha / 2)
x = r * cos(alpha / 2) + sagitta
y = width * x / sqrt(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(sagitta * (2 * x - sagitta)) / 2

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()

結果圖

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM