沿弧线找到一个点

3

我正在尝试编写一个Python或JavaScript例程,以找到弧线上的两个点。

我将使用起始距离和结束距离进入该例程。我想要绕弧形圆周移动一定距离,然后返回新的x和y坐标。实际上,我正在尝试移动我的弧线的起始点和结束点。

我的例程输入将是:

def get_points_on_an_arc(x1, y1, x2, y2, radius, large, clockwise, start_distance, end_distance)
     # logic here
     return s_x, s_y, e_x, e_y

这是一张或许可以帮到你的图片。

在此输入图片描述

有没有想法如何编写这个?

谢谢。


请问您能解释一下所有传递的参数和返回值成员的含义吗?这里的“给定金额”是指什么? - Teemu
我刚刚添加了一张图片来帮助。 - Thomas Turner
好的,距离是以弧度或者rad*r为单位吗?而且 large=false 只是另一种说法,表示“从(x1,y1)顺时针方向”。 - Teemu
我认为它是弧度。 - Thomas Turner
两个点和一个半径不能唯一确定一个圆,存在两种可能的解。 - Joni
3个回答

2

首先,您需要找到圆心。它位于P1-P2线段的中垂线上。即为两点连线的中点。

M = (P1 + P2)/2  
P12 = P2-P1 = (P12.X, P12.Y)

垂直于P12向量的是

PP = (-P12.Y, P12.X)

居中
C = M + PP * t 其中t是参数。
你需要解决这个方程。

(C-P1)^2 = R^2

针对t参数,选择两种可能的解决方案来满足需求(大的、顺时针的)
(例如,通过CP1和CP2的数量积符号)

找到中心后,问题的其余部分就很容易了:围绕中心将P1旋转(StartDistance/R)角度,并将P2旋转(-EndDistance/R)角度。


0
class Circle(object):
    def __init__(self, center=(0,0), radius=1):
         """ Center and radius define a unique circle """
         self._center = center
         self._radius = radius
    ...

    def isOn(self, point):
        if point_on_circle:
            return True
        return False
    ...

    def get_new_point(self, start=(1,0), distance=1, direction='clockwise'):
        """ Inputs:
          circle - instance of the Circle() class
          start  - tuple of (x, y) the exists on circle
          distance - distance to travel in radians
          direction - 'clockwise' or 'widdershins'
        """
        assert circle.isOn(start), "Start point is NOT on the circle"
        # code to calculate new point here - basic geometry, use Google
        end = ...
        return end

    def get_points_on_an_arc(self, x1, y1, x2, y2, large, clockwise, start_distance, end_distance):
        """ Your function signature will ONLY work if it is a class method 
            The alternative is to change the signature and explicitly pass in a Circle() object to the function
        """
        s_x, s_y = get_new_point(start=(x1, y1), distance=start_distance, direction='clockwise')
        e_x, e_y = get_new_point(start=(x2, y2), distance=end_distance, direction='widdershins')
        return s_x, s_y, e_x, e_y

0

解决方案

我已经编写了这段代码:

代码

class Circle:
    def __init__(self, rds):
        '''rds:radius    delete:ctr:center   of circle'''
        self.rds = rds

    def isoncircle(self, point):
        '''a check if point is on circle'''
        if point_on_circle:
            return True
        return False

    def get_point(self, start=[0, 0], distance=2, direction='c'):
        '''start:bottom point   distance:distance to move up or down    direction:move up or down'''
        if direction == 'c':
            cme = [start[0]+abs(distance-self.rds), start[1]+abs(distance-self.rds)]
        elif direction == 'cou':
            start = [start[0], start[1]-(self.rds*2)]
            cme = [start[0]-abs(distance-self.rds), start[1]-abs(distance-self.rds)]
        if self.isoncircle(cme):
            return cme

    def get_points(self, sd, ed):
        s_x, s_y = self.get_point(distance=sd, direction='c')
        e_x, e_y = self.get_point(distance=ed, direction='cou')
        return s_x, s_y, e_x, e_y

circle = Circle(4)
circle.get_points(4, 4)

类函数

init 函数完成所有设置。

isoncircle 函数检查一个点是否在圆上。

get_point 函数获取一个终点。

get_points 函数总结一切并获取两个端点。

摘要

仔细观察,您可以在 get_point 函数中更改距离甚至起始点。

如果有任何不清楚的地方,请告诉我。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接