Java-Gaming.org Hi !
 Featured games (91) games approved by the League of Dukes Games in Showcase (756) Games in Android Showcase (229) games submitted by our members Games in WIP (842) 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 2027 times) 0 Members and 1 Guest are viewing this topic.
wreed12345

JGO Knight

Medals: 28
Projects: 3
Exp: 5 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: 382
Projects: 11
Exp: 4 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: 5 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

JGO Kernel

Medals: 517

 « 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

 DesertCoockie (52 views) 2018-05-13 18:23:11 nelsongames (83 views) 2018-04-24 18:15:36 nelsongames (74 views) 2018-04-24 18:14:32 ivj94 (759 views) 2018-03-24 14:47:39 ivj94 (87 views) 2018-03-24 14:46:31 ivj94 (643 views) 2018-03-24 14:43:53 Solater (102 views) 2018-03-17 05:04:08 nelsongames (184 views) 2018-03-05 17:56:34 Gornova (426 views) 2018-03-02 22:15:33 buddyBro (1086 views) 2018-02-28 16:59:18
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 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