Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Math 2d: How to find the radius of an oval - based on point in world

Author
Message
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 15th Jul 2016 17:55
Hi

1. I Need to find the radius of an oval shaped sprite based on a point x,y in world.


If anyone have the answer - great.

2. I want to dig into collision detection and stuff related to geometric shapes....
If anyone have a link on the subject related to game collision detection - fantastic.

Tim
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 19th Jul 2016 02:56
Need way more information than just a random XY point in space. Center of oval? width? height? Anything?

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 19th Jul 2016 08:20
Quote: "I Need to find the radius of an oval shaped sprite based on a point x,y in world."


The radius of an oval is different, depending on the angle.
Also, do you mean ellipse? An oval can mean many different things, with many different formulas depending on what kind of oval it is.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 19th Jul 2016 09:19
Without more information, it is difficult to know exactly what you are after. If it is an oval shaped sprite, then you might want to detect a hit on that sprite using those x,y coords and simply return the sprite width... i.e. something like:



(where MyOvals is the group number assigned to your oval sprites).

V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 19th Jul 2016 09:49
If the ellipse doesn't have to rotate, then it should be quite straightforward, like say it was a circle....
dx#=px#-cx#
dy#=py#-cy#
d#=sqrt((dx#*dx#)+(dy#*dy#))

So you would check d# with the radius, if its less than then px#,py# is inside the circle.

Now to do the same for a non rotated ellipse, you'd use a factor on the dx# and dy# values. If the ellipse is double height for example, the X radius might be 5, and the Y radius 10... so you'd pick an axis, and work out the factor for the other axis, then apply that to dx# and dy#, to adjust to make it compatible with standard square root distance checks.
rx#=5.0
ry#=10.0
dx#=(px#-cx#)*(ry#/rx#)
dy#=(py#-cy#)
d#=sqrt((dx#*dx#)+(dy#*dy#))

I'm guessing, but I think you'd only have to adjust 1 axis, as it's a factor based on the other axis, so in this test the X difference is multiplied by 2, =10.0/5.0, or radius y / radius x... a collision would be detected when d# is less than ry# (10.0), as the X difference is adjusted based on the Y radius.

If the ellipse has to rotate, then I'd back away slowly from the math, and use Box2D instead.
The code is dark and full of errors
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 19th Jul 2016 14:03 Edited at: 19th Jul 2016 15:10
Hi. Thanks for your answer.

Im sorry about my lack of specifics - here they are.
I really mean an ellipse.

I've read a lot of articles now but my algebra is not strong. But based on Wikipedias page on ellipse https://en.wikipedia.org/wiki/Ellipse It seems that I'm after the "Polar form relative to centre".

My pointer is an ellipse sprite (The ellipse can be changed by the user. e.g. The x width could be more than the y height or vice versa)
I have a point on screen lets say (x=140, y=160)
The collision detection between the ellipse sprite and this point is no problem (I just use GetSpriteCollision). What I need to do is find the angle of the world point (140,160) relative to the center of the ellipse. And then find width of the ellipse at that angle (or the radius of the ellipse at that angle.)

The post : http://math.stackexchange.com/questions/432902/how-to-get-the-radius-of-an-ellipse-at-a-specific-angle-by-knowing-its-semi-majo
wants the same thing. But I'm not able to calculate the angle needed for the formula.
This is the image for that page - it shows what I need.

I need to find the r value in the picture

Hope this is clearer...

VAN B: I got your calculation now and Im getting closer. This gives me a very precise collision detection - but Im not sure how to calculate the radius based on this. The radius should be constant based on the angle.
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 19th Jul 2016 14:26
VAN B: Ah. I got it now. What you did suits me perfectly. Thank you
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 19th Jul 2016 17:59 Edited at: 19th Jul 2016 18:02
if it is for your game with brushes and energy calculation maybe this is also useful

GetWorldXFromSprite( iSpriteIndex, x, y )
GetWorldYFromSprite( iSpriteIndex, x, y )
GetSpriteInCircle( iSprite, x1, y1, radius )
GetSpriteDistance( iSprite1, iSprite2 )

my idea behind is filling your brushes with small "circles"
that means you get world position from a relative position in a brush.
then you can test if your sprite is inside your circle and you have a distance.
(for every position test)
AGK (Steam) V2.0.20 : Windows 10 Pro 64 Bit : AMD (16.3.2) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)

Attachments

Login to view attachments
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 22nd Jul 2016 20:26
Quote: "If the ellipse has to rotate, then I'd back away slowly from the math,"


lol Van!

Did you find your solution Tim?

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Login to post a reply

Server time is: 2024-04-20 00:24:46
Your offset time is: 2024-04-20 00:24:46