Notifications
Clear all

[Closed] Closest poly edge to a point?

If I have an editable poly, and I want to figure out which edge on that editable poly comes closest to a point in space, what do I need to do? Since an edge is basically a line segment I can’t just check the line, and because concavity may exist, I can’t just find the edge connecting the 2 closest vertices (they may not share an edge).

I can’t just use the midpoints of the edges either… if a long line comes the closest to intersecting the point, but the other end is far away, it won’t work.

The problem might look easier tomorrow… it’s been a long day and I’m frazzled. But any suggestons anyone has would be appreciated!

1 Reply

Hi Kevin, as first chance I’d say:

set starting minimum distance equal to a very big value i.e. 1e9

for every edge in Editable poly do
  get point-line distance
    if the distance is minor than current minimum distance then
      get point-line projection
        if projection point is included in edge segment then
          store the current edge index as closest and its distance as minimum

You may want to run a pre-loop where you store every Editable Poly vertex position in a Point3 Array to avoid querying it twice or more because for each vertex there are at least two edges. Using polyOp.getEdgeVerts should be faster than polyOp.getVertsUsingEdge, but I’m not completely sure.

You can find needed functions on IllusionCatalyst website, in MaxScript page.

  • Enrico