[solved] Placing arbitrary point on wire and finding the landing edge

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
stefankorisnik3
Posts: 101
Joined: Sun Jul 24, 2022 12:49 pm

[solved] Placing arbitrary point on wire and finding the landing edge

Post by stefankorisnik3 »

Having a wire. Let's place arbitrary point on wire. How to find the edge or vertex on which the point have landed?

My try: https://imgur.com/q9doR2D
Last edited by stefankorisnik3 on Sun Aug 07, 2022 10:33 pm, edited 1 time in total.
edwilliams16
Veteran
Posts: 3108
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Placing arbitrary point on wire and finding the landing edge

Post by edwilliams16 »

wireshape.distToShape(pointshape) contains the information.
stefankorisnik3
Posts: 101
Joined: Sun Jul 24, 2022 12:49 pm

Re: Placing arbitrary point on wire and finding the landing edge

Post by stefankorisnik3 »

Thanks
stefankorisnik3
Posts: 101
Joined: Sun Jul 24, 2022 12:49 pm

Re: [solved] Placing arbitrary point on wire and finding the landing edge

Post by stefankorisnik3 »

Does the wireshape.distToShape(pointshape) returns the number of edge - 1 in the property Edges or in the OrderedEdges as last element in the result array?
stefankorisnik3
Posts: 101
Joined: Sun Jul 24, 2022 12:49 pm

Re: [solved] Placing arbitrary point on wire and finding the landing edge

Post by stefankorisnik3 »

And can you let me know what are the values in the result? I get the following result for one interation of givenVertex.Shape.distToShape(c1Shape.Shape) where c1Shape is wire:

Code: Select all

(0.0001671146324180315,
[(Vector(46.8228, 0.856581, 151.443), Vector (46.82279999312901, 0.8565813537780497, 151.44316711425782))],
 [('Vertex', 0, None, 'Edge', 27, -23.175707956922878)])
Does this means that the landing is on the 27 - 1 edge in the property Edges in the wire?
Also is this consistent do is the 'Edge' always the fourth element of the [-1] of the result?
edwilliams16
Veteran
Posts: 3108
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: [solved] Placing arbitrary point on wire and finding the landing edge

Post by edwilliams16 »

Code: Select all

box = Part.makeBox(10,10,10)
Part.show(box, 'Box')
p = Part.Plane(App.Vector(6, 6, 6),  App.Vector(1,1,1)).toShape()
Part.show(p, "Plane")
wire = box.section(p)
Part.show(wire, 'Wires')
dist, vectors, infos = wire.distToShape(box)
if dist == 0.0:
    for i, info in enumerate(infos):
        print(f'Box {info[3]}{info[4] + 1} at u = {info[5]} at {vectors[i][1]} | Wire {info[0]}{info[1] + 1}')
else:
    print('No intersection\n')
To dig the info from distToShape()
Post Reply