如何在3D中找到圆上两点之间的点?

时间:2016-12-09 15:28:26

标签: python python-2.7 math

我有一个3D圆形(通过圆心所在的平面的中心,半径和法线定义),以及圆圈上的两个点p1和p2。我怎样才能找到两个点,即p3和p4,这两个点在两个给定点之间准确(即相等距离),但在圆圈上?

我的方法如下所示。对于某些点,例如在给定的例子中,我得到了预期的结果(p3 = [45.87,38.43,38.97]和p4 = [54.13,41.57,21.03]),但情况并非总是如此。与符号/方向和/或p1和p2与中心对齐时有关。我仍然无法弄清问题是什么。我的计算中没有使用n1。

import numpy as np

p1 = np.array([42.96, 46.23, 33.42])
p2 = np.array([52.91, 32.21, 35.55])
center = np.array([50, 40, 30])
radius = 10
n1 = np.array([0.64233475, 0.53814965, 0.54571148])

def FindIntermPtsOnCircle(p1, p2, center, radius):

    # Calculate the direction vectors of the given points from the center
    v1 = p1-center
    v1 = v1/np.linalg.norm(v1)
    v2 = p2-center
    v2 = v2/np.linalg.norm(v2)

    # Use bisecting line to find direction of the points of interest
    va1 = v1+v2
    va1 = va1/np.linalg.norm(va1)
    va2 = -va1

    # Multiply direction with radius to find relative distance and add to center
    p3 = va1*radius + center
    p4 = va2*radius + center

    return p3, p4

1 个答案:

答案 0 :(得分:1)

系统在p1,2完全相反时确定,然后你的v1,2加0,所以没有" bisector"等式中的va1

你可以使用条件(检查交叉产品v1,2 == 0或只是| va1 + va2 | == 0)然后使用正常的交叉产品来生成"补丁"对于那种情况或使用正常的交叉产品从一开始就为圆形平面构建一个基础,以制作一个不需要条件的公式

    def FindIntermPtsOnCircle(p1, p2, center, normalv):

    # Calculate the vectors of the given points from the center
    v1 = p1 - center
    v2 = p2 - center
    # Use bisecting line to find direction of the points of interest
    # check for special case of v1,2 colinear, opposite sides, adding to Zero    
    va1 = v1 + v2
    if  np.vdot(va1, va1) == 0:     # if v1,2 colinear, opposite use
        va1 = np.cross(normalv, v1) # norlmalv to calculate
                                    # a "bisector" in circle plane
    else:
        va1 = va1 * (np.vdot(v1, v1) / np.vdot(va1, va1)**(1/2))

    # reverse direction of va1 to get other bisector: va2
    va2 = -va1

    # add to center
    p3 = va1 + center
    p4 = va2 + center

    return p3, p4