Finding closest edge on a ConvexPolygonShape3D to point

Godot Version

v4.2.1.stable.official

Question

I have a point in 3D space and a ConvexPolygonShape3D with all it’s points in a PackedVector3Array. The points position and the Shapes positions are all relative to the physics body.

The thing is, the ConvexPolygonShape3D gives all the point positions however, I’m trying to find the closest edge to the point but i have literally no idea how. All I ask for is an algorythm which finds the closest edge to the point (by giving the two points which form the edge) and performance wise I don’t really care that much cus it won’t run every frame and my shapes are quite simple.

NOTE :
I thought about first finding the closest point on the shape to the point in space and then trying to find all the edges connected to that point on the shape so I wont have to check EVERY edge on the WHOLE SHAPE, but even that seems challenging, cus how do I know if another point is connected to this one or not?
I feel like there must be some kind of inequality which tells whether two points are connected or not.

All help appriciated!

There is no API to get the edges back from convexpolygonshape as far as I can tell, so I think this will be difficult. What were you trying to do with this calculation? Maybe there is some other way to approach it?

Im implementing a rope using raycast. When the raycast hits a physics object it the rope would separate into two parts. The second raycasts position would sit at the edge of the colliders shape closest to the intersection point. I would use Geometry3D.get_closest_point_to_segment() to get the point but this requires me to find the edge first.

Hmm yeah I don’t think there is any way of doing it. I would probably just go for estimating where the edge is with several raycasts.

1 Like