已解决:绘制圆弧的y值

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了已解决:绘制圆弧的y值相关的知识,希望对你有一定的参考价值。

解决方案>>

这里是最终的解决方案,我对数学及其所有原理的了解不是100%,但是如果有人在同一个问题上苦苦挣扎-我希望这会有所帮助。

圈子类别可以在下面的原始问题中找到。 Find附带了最终代码,该代码为我提供了所要提供的功能-根据圆弧长度(大圆距)在图形上模拟地球的曲率。

非常感谢所有花时间回答我并在整个过程中帮助我的人。

from circle import Circle
import numpy as np
import matplotlib.pyplot as plt

def calcStartAngle(startY,centreY,startX,centreX):
    startAngle = np.arctan2(startY-centreY, startX-centreX)
    return startAngle

def calcEndAngle(endY,centreY,endX,centreX):
    endAngle = np.arctan2(endY-centreY, endX-centreX)
    return endAngle

def main():
    distance = 200
    radius = 3440.065

#create circle object
c1 = Circle(radius,distance)
angle = c1.getDegrees()
xc = c1.getXc()
yc = c1.getYc()

#set start and end points
x1,y1 = 0,0
x2,y2 = distance,0

#get start and end angles
startAngle = calcStartAngle(y1,yc,x1,xc)
endAngle = calcEndAngle(y2,yc,x2,xc)
angleList = np.linspace(startAngle,endAngle,distance)
x_values = np.linspace(x1,x2,distance)
y_valuesList = []

for i in range(len(x_values)):
    y = radius*np.sin(angleList[i]) - c1.getArcHeight()
    y_valuesList.append(y)

#Create numpy array to hold y values
y_values = np.array(y_valuesList)

plt.ylim(0,50)
plt.plot(x_values,y_values)
plt.show()

if __name__ == "__main__":
     main()

这里是成品示例-

https://i.gyazo.com/1377cdd9d7eefe5608bc4c1dd2b3964e.png

原始问题

我正在尝试在matplotlib中将圆弧(2D)的段绘制为圆弧。我写了一堂课,将提供该段的数学信息,例如弦长,弧高等。我希望绘制x y值在(0,0)和(0,弦长)之间。

我目前将X值表示为numpy linspace数组(0,chordLength,200)。我对如何将y值绘制为类似的linspace数组感到有些困惑,以便可以使用matplotlib绘制这些点。其背后的想法是显示已知弧长(大圆距)的两个点之间的地球曲率。我一直在阅读正弦余弦等信息,但是在使用曲奇刀具公式进行几何计算之外,我对于如何应用它来获得y值有些迷失。

首先,圈子课

import numpy as np

class Circle:

    def __init__(self,radiusOfCircle,lengthOfArc):
        self.radius = radiusOfCircle
        self.circumference = 2 * np.pi * self.radius
        self.diameter = self.radius * 2
        self.arcLength = lengthOfArc
        self.degrees = self.calcDegrees()
        self.radians = self.calcRadians()
        self.chordLength = self.calcChordLength()
        self.sagitta = self.calcSagitta()
        self.segmentArea = self.calcSegmentArea()
        self.arcHeight = self.calcArcHeight()

    #Setters and getters for the Circle class (TODO: setters)
    def getRadius(self):
        return self.radius

    def getCircumference(self):
        return self.circumference

    def getDiameter(self):
        return self.diameter

    def getArcLength(self):
        return self.arcLength

    def getRadians(self):
        return self.radians

    def getDegrees(self):
        return self.degrees

    def getChordLength(self):
        return self.chordLength

    def getSagitta(self):
        return self.sagitta

    def getSegmentArea(self):
        return self.segmentArea

    def getArcHeight(self):
        return self.arcHeight

    #Define Circle class methods

    #Calculate the central angle, in degrees, by using the arcLength
    def calcDegrees(self):
        self.degrees = (self.arcLength / (np.pi * self.diameter)) * 360 #Gives angle in degrees at centre of the circle between the two points (beginning and end points of arcLength)
        return self.degrees

    #Calculate the central angle in radians, between two points on the circle
    def calcRadians(self):#Where theta is the angle between both points at the centre of the circle
        self.radians = np.radians(self.degrees) # Convert degrees to radians to work with ChordLength formula
        return self.radians

    #Returns the chord lengths of the arc, taking theta (angle in radians) as it's argument
    #The chord is the horizontal line which separates the arc segment from the rest of the circle
    def calcChordLength(self):
        self.chordLength = 2*self.radius*np.sin(self.radians/2) #formula works for theta (radians) only, not degrees #confirmed using http://www.ambrsoft.com/TrigoCalc/Sphere/Arc_.htm
        return self.chordLength

    #Calculates the length of arc, taking theta (angle in radians) as its argument.
    def calcArcLength(self):
        self.arcLength = (self.degrees/360)*self.diameter*np.pi #confirmed using http://www.ambrsoft.com/TrigoCalc/Sphere/Arc_.htm
        return self.arcLength

    #Calculates the sagitta of the arc segment.  The sagitta is the horizontal line which extends from the bottom
    #of the circle to the chord of the segment
    def calcSagitta(self):
        self.sagitta = self.radius - (np.sqrt((self.radius**2)-((self.chordLength/2)**2))) #Confirmed correct against online calculator https://www.liutaiomottola.com/formulae/sag.htm
        return self.sagitta

    #Calculates the area of the circular segment/arc).
    def calcSegmentArea(self):
        self.segmentArea = (self.radians - np.sin(self.radians) / 2) * self.radius**2
        return self.segmentArea

    #Calculate the height of the arc
    #Radius - sagitta of the segment
    def calcArcHeight(self):
        self.arcHeight = self.radius - self.sagitta
        return self.arcHeight

我在主程序方面进展不大,因为我要做的首要任务之一就是创建y值。这是我到目前为止的内容-

from circle import Circle
import numpy as np
import matplotlib.pyplot as plt

def main():
    #define centre point

    #Circle(radius,arc length)
    c1 = Circle(3440.065,35) #Nautical miles radius with 35Nm arc length
    chordLength = c1.getChordLength()
    arcHeight = c1.getArcHeight()

    centerX = chordLength/2
    centerY = 0

if __name__ == "__main__":
    main()

对于上下文,我希望使用此“弧”向-https://link.ui.com/#添加高程数据。我希望模拟随距离增加的曲率,我可以将其用于粗略的视线分析。

但是,第一步是获取y值。

解决方案这是最终的解决方案,我对数学及其所有原理的了解不是100%,但是如果有人在同一个问题上苦苦挣扎-我希望这会有所帮助。圆类可以在...

答案

要绘制弧高作为弦长的函数,您可以遍历一定范围的弧长并将相应的弧高和弦长存储到数组中。

另一答案

这里是最终的解决方案,我对数学及其所有原理的了解不是100%,但是如果有人在同一个问题上苦苦挣扎-我希望这会有所帮助。

以上是关于已解决:绘制圆弧的y值的主要内容,如果未能解决你的问题,请参考以下文章

绘制透明圆弧

CAD参数绘制圆弧(网页版)

CAD参数绘制圆弧(com接口)

canvas绘制圆弧

移动起点后找到绘制圆弧的公式

如何在 OpenGL 中绘制圆弧