somebody recently asked for a snippet to compute the distance between two points along a curved line (a "wire body" Entity).
import XCoreModeling
import XCoreMath
Vec3 = XCoreModeling.Vec3
Body = XCoreModeling.Body
def geodesic_distance_curve(wire_body: Body, p1: Vec3, p2: Vec3):
wires = XCoreModeling.GetWires(wire_body)
assert len(wires) == 1
curve = wires[0].GetGeometry(transform_to_model_space=True)
u1 = curve.MinDistParameter(p1)
u2 = curve.MinDistParameter(p2)
return abs(curve.Length(u1, u2))
And here is an example how to use it:
if __name__ == "__main__":
ent = XCoreModeling.CreateSpline([Vec3(0), Vec3(1, 1, 0), Vec3(2, 0, 0), Vec3(3, 1, 0), Vec3(4, 0, 0)])
d = geodesic_distance_curve(ent, Vec3(1, 1, 0), Vec3(3, 1, 0))
print(f"{d} != 2")