Finding the nearest point to a shape.

Started by
5 comments, last by Vortez 9 years, 10 months ago

Hello, I've been trying to figure something out that seems rather simple, but I'm just not sure on the type of math I should be using. I'm trying to find the nearest point on the surface of a shape from the center of a sprite (blue ball). If anyone could point me in the right direction that'd be great, I have included an image below. I was thinking I'd need to use some kind of vector math, so any help is greatly appreciated.

xQgmfGs.png?1?8544

Advertisement


find the nearest point on the surface of a shape

More information is needed to help you out, as it depends on how you have the shape defined. Is it procedural? Defined by vertices? A drawn & filled shape?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Use GJK. GJK works via "support functions" which can map mathematical shapes (curves) or vertex-based shapes. The result of GJK is the shortest distance between two points on the surface of the shapes, which necessarily gives you the points as well.

Sean Middleditch – Game Systems Engineer – Join my team!


find the nearest point on the surface of a shape

More information is needed to help you out, as it depends on how you have the shape defined. Is it procedural? Defined by vertices? A drawn & filled shape?

The shape would be drawn and filled. Would it be possible to use some kind of pixel level testing or could this potentially all be done through vector math?


Would it be possible to use some kind of pixel level testing .. ?

Most likely.


.. could this potentially all be done through vector math?

Maybe.

You're new to the site (and welcome!) so you should learn how to post an effective question.

First thing would be to read about posting to the forums. Although that link is about the Beginner's forum, there's a lot of good stuff that will help you get better answers to your questions. E.g., take a look under Asking Questions, at the line that begins "Be as descriptive as you can.."

The reason I'm redirecting you to that page is because your post so far is: "I'm drawing a shape. What's the distance from here to there?" See the problem?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

You can do this easily by calculating the perpendicular distance to each line comprising the polygon, as well as checking each vertex.

The perpendicular distance be calculated like this http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html

If all you need is to calculate the distance between one of the box corner to the sprite center, just use the distance formula.

dist07b.gif

Do this for each 4 points of the box and the shortest value will be the nearest one.

This topic is closed to new replies.

Advertisement