提问人:Ans shakeel 提问时间:9/5/2023 最后编辑:Ans shakeel 更新时间:9/6/2023 访问量:64
在 3D 空间中绘制一个面向方向矢量的圆
Draw a Circle in 3D space facing towards Direction Vector
问:
我会尽量清楚地解释。
目标:围绕 3D 空间中面向方向矢量的中心点绘制一组圆形点。尝试使用 VTK python 对圆柱体和弯曲模型进行建模,以便在 3D 空间中生成点,然后将它们连接起来以在其上放置一个表面。
方法:假设我有一个中心点 center(x,y,z) 和方向向量direction_vector。我将计算点中心的正交基,定义一个平面,并在平面上生成指向方向向量的点。
def generate_circular_points_v2(center, radius, direction_vector, num_points=12):
circular_points = []
v1 = np.cross(direction_vector, [1.0, 0.0, 0.0])
if np.all(v1 == 0):
v1 = np.cross(direction_vector, [0.0, 1.0, 0.0])
v2 = np.cross(direction_vector, v1)
v1 /= np.linalg.norm(v1)
v2 /= np.linalg.norm(v2)
angles = np.linspace(0, 2 * np.pi, num=num_points, endpoint=False)
for angle in angles:
v1_Out = np.cos(angle) * v1
v2_Out = np.sin(angle) * v2
point = center + (radius * (v1_Out + v2_Out ))
circular_points.append(point)
return circular_points
下面的代码绘制一条贝塞尔曲线,然后在曲线的每个点上添加圆环。
# generating points for Bezier Curve
# it takes 3 Control points, 1st one is starting point, 2nd on is Tangent Intersection Point
# and 3rd one is the ending point, it makes a 90 degrees angle bend
pointListBEND = []
for i in range(0 , 10):
i=i/10
pts = quadratic_bezier(ptsA ,cornerPointBend , ptsB , t = i)
pointListBEND.append(pts)
# GENERATING Circular Rings on each Point of Bezier Curze
for itr in range(0,len(pointListBEND)):
if itr + 1 < len(pointListBEND):
dirVec = getNormalizedDirVec(pointListBEND[itr+1],pointListBEND[itr])
circularPoints = generate_circular_points_v2(center=pointListBEND[itr],
radius=tempRadius,direction_vector=dirVec)
# Adding Points to VTK array
for p in circularPoints:
vtkPoints.InsertNextPoint(p)
现在,代码用于在点上添加三角形条以添加实体曲面。
def AddTriangles(vtkpoints, count):
theta_resolution = count
phi_resolution = 12
torus_cells = vtk.vtkCellArray()
for i in range(theta_resolution+4 ):
for j in range(phi_resolution):
torus_cells.InsertNextCell(4) # Number of points in each triangle strip
torus_cells.InsertCellPoint(i * phi_resolution + j)
torus_cells.InsertCellPoint(i * phi_resolution + (j + 1) % phi_resolution)
torus_cells.InsertCellPoint((i + 1) * phi_resolution + j)
torus_cells.InsertCellPoint((i + 1) * phi_resolution + (j + 1) % phi_resolution)
return torus_cells
它工作得很好,但是当方向向量 (NORMALIZED) 为 时,存在一种例外情况,这会导致:V = [-0.99861783, 0., 0.05255883]
v1 = [ 0.,0.05255883,-0.]
v2 = [-0.00276243, 0., -0.05248619]
这是圆环旋转一点并移动导致扭转的点的点,圆柱体连接的地方。
是什么导致了这个问题?
还有一件事,我使用贝塞尔曲线绘制这个弯曲形状,然后在贝塞尔曲线的每个点上在曲线点传播方向上生成圆环(Direction VECTOR (CurvePoint[index + 1] - CurvePoint[index])
)
答: 暂无答案
评论
V
normal
def...