## How to get on the most efficient way the Shape.BoundBox.XMax point?

Need help, or want to share a macro? Post here!
stefankorisnik3
Posts: 99
Joined: Sun Jul 24, 2022 12:49 pm

### How to get on the most efficient way the Shape.BoundBox.XMax point?

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?
edwilliams16
Veteran
Posts: 1447
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

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)``````
which will tell you where on shp the closest point is (at distance zero).
stefankorisnik3
Posts: 99
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

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>]``````
edwilliams16
Veteran
Posts: 1447
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)
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), 'VertexEW')``````
Both ways work. Your way relies on OCCT's internal mechanisms to handle rounding error - which is probably OK. Mine is explicitly tolerant as it finds the closest point, not the intersection. You can show this by adjusting the plane location by, say, +1e-5, your method then fails.

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.
stefankorisnik3
Posts: 99
Joined: Sun Jul 24, 2022 12:49 pm