简体   繁体   English

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

[英]How to find the point between two points on a circle in 3D?

I have a circle in 3D (defined through a center, radius, and normal to the plane where the circle lays in), and two points, p1 and p2, that lay on the circle. 我有一个3D圆(通过中心,半径和圆所在的平面的法线定义),圆上有两个点p1和p2。 How can I find the two points, p3 and p4, that lay exactly (ie equal distance) between the two given points, but on the circle? 我如何找到两个给定点p3和p4,它们恰好位于两个给定点之间(即相等的距离),但在圆上?

My approach is shown below. 我的方法如下所示。 For some points, like in the given example, I'm getting the expected results (p3 = [45.87, 38.43, 38.97] and p4 = [54.13, 41.57, 21.03]), but this is not always the case and might have to do with the signs/directions and/or when p1 and p2 are in line with the center. 对于某些方面,例如在给定的示例中,我得到了预期的结果(p3 = [45.87、38.43、38.97]和p4 = [54.13、41.57、21.03]),但这并非总是如此,可能必须请与符号/方向和/或p1和p2与中心对齐。 I still haven't figured out what the problem is. 我仍然没有弄清楚问题是什么。 n1 is not used in my calculation. 我的计算中未使用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

the system is under determined when p1,2 are exactly opposite, then your v1,2 add to 0 so there is no "bisector" va1 from your equation 当p1,2正好相反时,系统处于确定状态,那么您的v1,2加到0,所以方程式中没有“平分线” va1

you can use a conditional ( check cross product v1,2 == 0 or just |va1 + va2| == 0 ) and then use cross product with the normal to generate a "patch" for that case or use the normal, cross product to construct a basis for the circle's plane from the start to make a formula that doesn't need the conditional 您可以使用条件(检查叉积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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM