【问题标题】:How to calculate points y position on arc? When i have radius, arcs starting and ending points如何计算圆弧上的点y位置?当我有半径时,弧的起点和终点
【发布时间】:2016-03-26 01:20:52
【问题描述】:

我正在尝试在 CNC 上编写程序。基本上我有圆弧开始 x, y ,半径和结束 x, y 我也知道弧的方向顺时针或 cc。所以我需要找出特定x位置的弧上y的值。最好的方法是什么? 我在这个网站here 上发现了类似的问题。但我不确定如何获得角度 a。

【问题讨论】:

  • 你只想要 y_random 还是也想要角度?
  • x=R cos(theta),所以 theta = arccos(x/R), y=R sin(theta)。您可能需要确保您在正确的象限中。
  • 对不起,我没有提到这个,而是它的圆弧。
  • francium 我只想得到 y_random。

标签: geometry automatic-ref-counting cnc


【解决方案1】:

首先你必须找到圆方程。让我们起点Pst = (xs,ys),终点Pend = (xend,yend)

为简单起见,将所有坐标移动(-xs, -ys),因此起点成为坐标原点。

新的Pend' = (xend-xs,yend-ys) = (xe, ye),新的“随机点”坐标是xr' = xrandom - xs,未知的圆心是(xc, yc)

xc^2 + yc^2 = R^2    {1}
(xc - xe)^2 + (yc-ye)^2 = R^2  {2}  //open the brackets
xc^2 - 2*xc*xe + xe^2 + yc^2 - 2*yc*ye + ye^2 = R^2    {2'}
subtract {2'} from {1}
2*xc*xe - xe^2  + 2*yc*ye - ye^2 = 0    {3}
yc =  (xe^2 + ye^2 - 2*xc*xe) / (2*ye) {4}
substitute {4} in {1}
xc^2 + (xe^2 + ye^2 - 2*xc*xe)^2 / (4*ye^2) = R^2 {5}
solve quadratic equation {5} for xc, choose right root (corresponding to arc direction), find yc

having center coordinates (xc, yc), write
yr' = yc +- Sqrt(R^2 -(xc-xr')^2) //choose right sign if root exists
and finally exclude coordinate shift
yrandom = yr' + ys

【讨论】:

    【解决方案2】:

    圆的方程是x^2 + y^2 = r^2

    在您的情况下,我们知道 x_randomR

    代入知道我们得到,

    x_random ^ 2 + y_random ^ 2 = R ^ 2
    

    解决y_randomget get

    y_random = sqrt( R ^ 2 - x_random ^ 2 )
    

    现在我们有y_random

    编辑:只有当你的弧是圆弧而不是椭圆弧时,这才有效

    要使这个答案适应椭圆,你需要使用这个方程,而不是圆的方程

    ( x ^ 2 / a ^ 2 ) + ( y ^ 2 / b ^ 2 ) = 1,其中a 是沿x axis 的半径,b 是沿y axis 的半径


    从名为data.txt 的文件中读取数据并计算一系列y_random 值并将它们写入名为out.txt 的文件的简单脚本

    import math                                                                 
    
    def fromFile():                                                             
        fileIn = open('data.txt', 'r')                                          
        output = ''                                                             
        for line in fileIn:                                                     
            data = line.split()                                                 
            # line of data should be in the following format                    
            # x h k r                                                           
            x = float(data[0])                                                  
            h = float(data[1])                                                  
            k = float(data[2])                                                  
            r = float(data[3])                                                  
            y = math.sqrt(r**2 - (x-h)**2)+k                                    
            if ('\n' in line):                                                  
                output += line[:-1] + ' | y = ' + str(y) + '\n'                 
            else:                                                               
                output += line + ' | y = ' + str(y)                             
        print(output)                                                           
        fileOut = open('out.txt', 'w')                                          
        fileOut.write(output)                                                   
        fileIn.close()                                                          
        fileOut.close()                                                         
    
    if __name__ == '__main__':                                                  
        fromFile()
    

    data.txt 应该这样格式化

    x0 h0 k0 r0
    x1 h1 k1 r1
    x2 h2 k2 r2
    ... for as many lines as required
    

    【讨论】:

    • 我认为圆的方程是 (x – h)^2 + (y – k)^2 = r^2。我错了吗? h, k 圆心。
    • @aidas h 和 k 用于沿 x 和 y 轴平移圆。如果不平移圆,h=0,k=0,则得到 x^2 + y^2 = r^2
    • 但在我的情况下,h 和 k 不是 0。我可以在我正在制作的程序中将每个弧线偏移到零。但我希望有更清洁的方法。
    • @aidas 对于每条弧线,计算仍然相同,唯一不同的是您插入的数字。您可以轻松编写一个简单的程序(例如 python)来接受您的数字并快速计算结果。
    • @fracium 你能告诉我它是怎么做的吗?蟒蛇很好。只是圆心是未知的。我找到了它的方程式here。只是我解决这个问题的数学技能还不够好。
    猜你喜欢
    • 2021-04-09
    • 1970-01-01
    • 2022-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    • 1970-01-01
    相关资源
    最近更新 更多