Skip to content
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

ZMT zurich med tech

  1. Home
  2. Sim4Life
  3. CAD Modeling
  4. Evaluate distance along a (curved) line

Evaluate distance along a (curved) line

Scheduled Pinned Locked Moved CAD Modeling
python
1 Posts 1 Posters 281 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • brynB Offline
    brynB Offline
    bryn
    ZMT
    wrote on last edited by Sylvain
    #1

    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")
    
    1 Reply Last reply
    1
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Search