Getting the point of a part that's the furthest from it in a given direction

Some time ago, I came over this post on the DevForum:

After looking at the solution, out of curiosity I started wondering if you could generalize it to work for any direction, not just the down way. I have spent quite a bit of time on this, but couldn’t get any good solution for it. That’s why I’m asking for help here. I don’t really know what I could use it for though, so if no solutions come up that’s ok.

You would use the dot product to calculate how far a point is in any direction you choose.

How exactly would you use the dot product for that? I’m not very familiar with dot products, so I can’t immediately come up with how to use them here.

The dot product tells you how far one vector points along another vector. So you choose the direction to be “down” from the original example, the for each corner you take the difference from the parts center and dot it with the down direction. The one with the highest dot product is the furthest along the down direction.

2 Likes

That would work for any direction Vector3, however, it would only work for the part’s corners. The original solution for the down direction works for any point along the edges of the part.

For a block the lowest point is always a corner. The original solution makes an exception if the part is exactly flat, in which case it returns the center of the face, from what I can see. To get that effect you can check if more than one corner has the same dot product, then average those corners position. That will have the effect of both giving you the center of the face if the part is flat, or the center of an edge if its resting on an edge. (This should also work for wedges and corner wedges)

1 Like

Thanks! This works exactly like how I envisioned.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.