Jump to content
  • Advertisement
Sign in to follow this  
Samcp19

Finding the nearest point to a shape.

This topic is 1490 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

 


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?

Share this post


Link to post
Share on other sites


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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!