[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 17 KB, 256x256, PolygonCollision01.png [View same] [iqdb] [saucenao] [google]
2261391 No.2261391 [Reply] [Original]

Hey /sci/

How do you check if two polygons are colliding, without using any built in classes (so the code can be converted easily)?

If you're kind enough to code it yourself, c++ and java are preferred.

>> No.2261411

>mfw the site you took the image from has the code for that.

>> No.2261418

Why do we have to code your polygon collision code? It is a problem that has been solved 2^infinity times already, google it.

>> No.2261423

>>2261418
Because I'm stupid and don't get the results from google :(

>> No.2261450

From the first google result for Polygon Collision, the separating axis theorem says that if the (convex) polygons are not intersecting, then one of the sides of one of the polygons has to lie along a line that separates the two polygons, which isn't an obvious conclusion. In the pic, that line is marked "edge".

Once you're testing for if a particular line separates the polygons you just have to change coordinates such that the line is along one axis, and see if all the points of one polygon are to greater than the value of the line, and all the points of the other are less than the value of the line, on that axis.

>> No.2261451
File: 167 KB, 634x734, 1291753825708.jpg [View same] [iqdb] [saucenao] [google]
2261451

use the algorithm from your picture

or cgal library (c++)

>> No.2261454

>>2261423
Separating Axis Test. Google that and/or GTFO. I'm stupid too but I can write SAT code. :)