Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (683) Games in Android Showcase (196) games submitted by our members Games in WIP (751) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
 Home Help Search Login Register
Pages: [1]
 ignore  |  Print
 Detecting Collision between a rectangle and a circle?  (Read 1262 times) 0 Members and 1 Guest are viewing this topic.
wreed12345

JGO Knight

Medals: 28
Projects: 3
Exp: 2 years

https://github.com/wreed12345

 « Posted 2012-12-02 01:16:29 »

how would i detect the collision between a rectangle and a circle? both of these are images btw.

HeroesGraveDev

JGO Kernel

Medals: 381
Projects: 11
Exp: 3 years

┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻

 « Reply #1 - Posted 2012-12-02 01:26:13 »

Here

Phibedy

Senior Devvie

Medals: 9

 « Reply #2 - Posted 2012-12-02 14:44:10 »

[CODE]public static boolean cricleVsRect(PCircle c, PRectangle p){
return true;
}
if(c.containsPoint(p.getLocation())
|| c.containsPoint(PVector.add(p.getLocation(), new PVector(p.getWidth(), 0)))
|| c.containsPoint(PVector.add(p.getLocation(), new PVector(0, p.getHeight())))
|| c.containsPoint(PVector.add(p.getLocation(), new PVector(p.getWidth(), p.getHeight())))
)
return true;
return false;
}
[/CODE]
"[rectangle].getLocation()" returns the upper left corner of the rectangle.
"[circle].getLocation()" returns the middle of the circle.

If it's possible to solve it faster, feel free to critizise
best regards
 Games published by our own members! Check 'em out!
wreed12345

JGO Knight

Medals: 28
Projects: 3
Exp: 2 years

https://github.com/wreed12345

 « Reply #3 - Posted 2012-12-02 15:35:03 »

i do not understand this at all...lol and i am getting a bunch of errors when trying to use this

Agro
 « Reply #4 - Posted 2012-12-02 16:16:18 »

wreed, you can just use AABB to do it. DrHalfway posted an article int he Articles section that explains the AABB method.

Phibedy

Senior Devvie

Medals: 9

 « Reply #5 - Posted 2012-12-03 17:21:29 »

PVector and PRectangle are custom classes. You can't just copy the code, but if you have questions about it, feel free to ask.
Roquen
 « Reply #6 - Posted 2012-12-03 17:58:39 »

http://www.java-gaming.org/topics/vectors-what-s-the-point/24307/msg/225743/view.html#msg225743
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 orrenravid (217 views) 2016-07-16 03:57:23 theagentd (288 views) 2016-07-11 14:28:54 Hydroque (375 views) 2016-07-06 05:56:57 Hydroque (527 views) 2016-07-03 08:52:54 GrandCastle (399 views) 2016-07-01 09:13:47 GrandCastle (392 views) 2016-07-01 09:09:45 CopyableCougar4 (445 views) 2016-06-25 16:56:52 Hydroque (420 views) 2016-06-22 02:17:53 SwampChicken (386 views) 2016-06-20 13:22:57 SwampChicken (306 views) 2016-06-20 13:22:49
 Archive 30x Slyth2727 24x Brynn 23x EgonOlsen 22x orangepascal 22x TritonDreyja 21x orange451 20x DavidBVal 19x Spasi 18x KaiHH 12x Opiop 11x princec 11x LiquidNitrogen 11x Phased 11x Longor1996 10x ziozio 10x
 Making a Dynamic Plugin Systemby Hydroque2016-06-25 00:13:25Java Data structures2016-06-13 21:22:09Java Data structures2016-06-13 21:20:42FPS Camera Tutorialby Hydroque2016-05-22 05:40:58Website offering 3D Models specifically for games for freeby vusman2016-05-18 17:23:09Website offering 3D Models specifically for games for freeby vusman2016-05-09 08:50:56Website offering 3D Models specifically for games for freeby vusman2016-05-06 11:10:21Website offering 3D Models specifically for games for freeby vusman2016-04-29 12:56:17
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org