我写了一个python脚本,它从查询点(p)中找到表面上最近点的UV坐标.表面由四个线性边缘限定,这四个线性边缘由逆时针列出的四个已知点(p0,p1,p2,p3)组成.
(请忽略小红球)
我的方法的问题是它非常慢(使用低精度阈值进行5000次查询约10秒).
我正在寻找一种更好的方法来实现我想要的,或者建议使我的代码更有效率.我唯一的限制是它必须用python编写.
import numpy as np
# Define constants
LARGE_VALUE=99999999.0
SMALL_VALUE=0.00000001
SUBSAMPLES=10.0
def closestPointOnLineSegment(a,b,c):
''' Given two points (a,b) defining a line segment and a query point (c)
return the closest point on that segment, the distance between
query and closest points, and a u value derived from the results
'''
# Check if c is same as a or b
ac=c-a
AC=np.linalg.norm(ac)
if AC==0.:
return c,0.,0.
bc=c-b
BC=np.linalg.norm(bc)
if BC==0.:
return c,0.,1.
# See if segment length …Run Code Online (Sandbox Code Playgroud)