gpt4 book ai didi

python - 连 catch 体表面上的两点

转载 作者:行者123 更新时间:2023-12-01 09:06:27 25 4
gpt4 key购买 nike

我需要连 catch 体上的两个点,这样线(边缘)就会停留在球体的表面上并且不会穿过它。

现在我有:

  1. 这个球体:Evenly distributing n points on a sphere

  2. 绘制了边缘,但它们穿过球体。

  3. 期望的结果:

最佳答案

这是 spherical linear interpolation 的实现或在此 answer 中提出的 slerp :

import numpy as np
import matplotlib.pylab as plt

def slerp(p1, p2, t):
omega = np.arccos( p1.dot(p2) )
sin_omega = np.sin(omega)
t = t[:, np.newaxis]
return ( np.sin( (1-t)*omega )*p1 + np.sin( t*omega )*p2 )/sin_omega

p1 = np.array([1, 0, 0])
p2 = np.array([0, 1, 0])
t = np.linspace(0, 1, 30)

arc = slerp(p1, p2, t)

plt.plot( arc[:, 0], arc[:, 1] );
plt.axis('square');

给出 2D 形式:

2D example

关于python - 连 catch 体表面上的两点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52007002/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com