How to get on the most efficient way the Shape.BoundBox.XMax point?
Do i need to travel through all points and compare to get the point that have as x-coordinate XMax?
Is there possibility to skip some points because rounding floats?
How to get on the most efficient way the Shape.BoundBox.XMax point?
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
-
- Posts: 101
- Joined: Sun Jul 24, 2022 12:49 pm
-
- Veteran
- Posts: 3192
- Joined: Thu Sep 24, 2020 10:31 pm
- Location: Hawaii
- Contact:
Re: How to get on the most efficient way the Shape.BoundBox.XMax point?
Looping through Vertices won't work because the bounding point isn't necessarily a Vertex = take a sphere, for instance
Try
which will tell you where on shp the closest point is (at distance zero).
Try
Code: Select all
plane_shp = Part.Plane(App.Vector(shp.BoundBox.XMax, 0, 0), App.Vector(1,0,0)).toShape() # YZ plane through Xmax
shp.distToShape(plane_shp)
-
- Posts: 101
- Joined: Sun Jul 24, 2022 12:49 pm
Re: How to get on the most efficient way the Shape.BoundBox.XMax point?
Can you take a look at following code
I get the vertex in intersection
I get the vertex in intersection
Code: Select all
>>> shp = Part.Sphere()
>>> shp.Center = App.Vector(0,0,0)
>>> shp.Radius = 3
>>> shp = Part.show(shp.toShape())
>>> shp
<Part::PartFeature>
>>> p = Part.Plane(App.Vector(shp.Shape.BoundBox.XMax, 0, 0), App.Vector(1,0,0)).toShape()
>>> Part.show(p)
<Part::PartFeature>
>>> r = shp.Shape.section(p)
>>> r
<Shape object at 000001E03CC6E1E0>
>>> r.Vertexes
[<Vertex object at 000001E0519DBE70>]
-
- Veteran
- Posts: 3192
- Joined: Thu Sep 24, 2020 10:31 pm
- Location: Hawaii
- Contact:
Re: How to get on the most efficient way the Shape.BoundBox.XMax point?
Code: Select all
sphere = Part.Sphere()
sphere.Center = App.Vector(0,0,0)
sphere.Radius = 3
shp = sphere.toShape()
Part.show(shp, 'Sphere')
p = Part.Plane(App.Vector(shp.BoundBox.XMax, 0, 0), App.Vector(1,0,0)).toShape()
Part.show(p, 'Plane')
r = shp.section(p)
Part.show(r, 'Vertex')
d = shp.distToShape(p)
Part.show(Part.Vertex(d[1][0][0]), 'VertexEW')
EDIT: the distToShape() method works here, for a sphere, but not for a cube when the plane intersects. So stick with the section() method.
Last edited by edwilliams16 on Sun Aug 07, 2022 11:30 pm, edited 1 time in total.
-
- Posts: 101
- Joined: Sun Jul 24, 2022 12:49 pm