围绕弧点绘制圆环 - VTK UnstructedGrid

问题描述 投票:0回答:1

我正在尝试围绕弧点创建圆环。我正在尝试在两点之间创建一个圆柱形弯曲。为此,我做了以下工作:

  1. 在两点之间画一条圆弧。为此,我在 3D 空间中有 2 个对角点,我使用这些点来查找正方形顶点,并使用其中一个正方形点作为中心点在两个对角点之间绘制一条 ARC。
def draw_square_from_diagonal_points(point1, point2):
    # Extract coordinates of the two diagonal points
    x1, y1,z1 = point1
    x2, y2,z2 = point2

    # Find the midpoint of the diagonal
    mx = (x1 + x2) / 2
    my = (y1 + y2) / 2

    # Calculate the difference vector between point1 and the midpoint
    dx = x1 - mx
    dy = y1 - my

    # Find the fourth corner point of the square
    bx = mx + dy
    by = my - dx

    # Define the four points of the square
    pointA = (x1, y1)
    pointB = (bx, by)
    pointC = (x2, y2)
    pointD = (mx - dy, my + dx)  # The fourth corner opposite to pointB
    return pointD 
def draw_arc(radius , center,num_points=16,circle_radius=1, cross_sections_radius = 0.5, circle_points=8):

    radian_angle = 2 * math.pi / num_points
    arc_points = []
    circle_pts = []
    for i in range(num_points):
        if i == num_points/4 + 1:
            break
        cal_angle = i * radian_angle
        xx = center[0] + radius * math.cos(cal_angle)
        yy = center[1] + radius * math.sin(cal_angle)
        zz = center[2]
        arc_points.append([xx,yy,zz])
return arc_points

以下是上述代码的示意图。 Illustraction of drawing ARC by finding the Center point

现在的问题是如何在这些圆弧点周围绘制圆环点?这些点应该处于那个方向,如果我们连接那些圆环点,它将形成如下所示的圆柱形弯曲结构: enter image description here

我尝试使用以下代码在圆弧点周围绘制圆点,它实际上绘制了,但点的方向不好。 代码:

def add_spherical_points(center, radius):
    
    phi_angle = math.pi / 6 #60 Angle
    circular_points = []
    newpts=[]
    for i in range(12):
        delta_angle = 2 * math.pi * i / 12
        #angle = i * delta_angle
        x = center[0] + radius * math.sin(phi_angle) * math.cos(delta_angle) 
        y = center[1] + radius * math.sin(phi_angle) * math.sin(delta_angle)
        z = center[2] + radius * math.cos(phi_angle)
        circular_points.append([x,y,z])

    return circular_points

enter image description here

opengl graphics geometry computational-geometry vtk
1个回答
0
投票

好的,要绕大圆弧上的点做圆,你需要计算一些向量。

大圆平面的法向矢量。在你的情况下,平面似乎平行于OXY平面(并且你正在使用

zz = center[2]
),所以正常是
n=(0,0,1)
,但在一般情况下,你必须获得两个正方形(ABCD)边的叉积

n = (AB x BC).normalized

现在从大圆心到当前圆弧点的单位向量。在你的情况下是

vr = (math.cos(cal_angle), math.sin(cal_angle))
,一般情况下表达式会更复杂(取决于预定义的数据)

有了这两个向量,就可以做点了

large_arc_point + r*n*cos(delta_angle) + r*vr*sin(delta_angle)
© www.soinside.com 2019 - 2024. All rights reserved.