Jump to content

  • Log In with Google      Sign In   
  • Create Account


Finding the nearest point to a shape.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Samcp19   Members   -  Reputation: 106

Like
0Likes
Like

Posted 23 May 2014 - 05:59 PM

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



Sponsor:

#2 Buckeye   Crossbones+   -  Reputation: 4005

Like
0Likes
Like

Posted 23 May 2014 - 06:31 PM


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.


#3 SeanMiddleditch   Members   -  Reputation: 4634

Like
0Likes
Like

Posted 23 May 2014 - 06:52 PM

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.

#4 Samcp19   Members   -  Reputation: 106

Like
0Likes
Like

Posted 23 May 2014 - 08:28 PM

 


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?



#5 Buckeye   Crossbones+   -  Reputation: 4005

Like
0Likes
Like

Posted 23 May 2014 - 10:13 PM


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.


#6 Vexal   Members   -  Reputation: 416

Like
1Likes
Like

Posted 26 May 2014 - 05:06 PM

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



#7 Vortez   Crossbones+   -  Reputation: 2688

Like
0Likes
Like

Posted 26 May 2014 - 09:50 PM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS