Algorithm for collision - any library in Python or other languages - or will someone do it? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

Algorithm for collision - any library in Python or other languages - or will someone do it?

Hi, I read about an algorithm that checkes a collision between lets say two triangles a and b. The idea looks easy on the first glance: add every point of a to every point if b so if a = (1,2),(3,3),(3,0) and b = (0,0),(1,1),(2,2) we have points (1,2),(3,3),(3,0),(2,3),(4,4),(4,0),(3,4),(5,5),(5,0) now create convex hull of this 9 points and check if (0,0) is in it. Although there is an algorithm as pseudo code https://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain I still have the last point to solve. Dont we have libraries for that?

7th Nov 2018, 3:20 PM
Oma Falk
Oma Falk - avatar
8 Answers
+ 3
You can find whether a given point lies inside the convex hull by checking whether it lies at the same side of each segment that forms the convex hull. If you have the hull in counterclockwise order, the O[0,0] point should be in counterclockwise direction from each segment AB on the hull, that is, the vector product AO x AB should be negative for all segments AB If it is in clockwise order, it should be always positive Is this what you are asking for?
7th Nov 2018, 4:01 PM
michal
+ 3
to be honest: Its an assignment for runaways.😇😇😇😇 so if you like... write a collisiin detector.
7th Nov 2018, 6:10 PM
Oma Falk
Oma Falk - avatar
+ 3
@michal thats true.. i remember wrong.. it was similiar. not add but substract?
7th Nov 2018, 6:15 PM
Oma Falk
Oma Falk - avatar
+ 2
I think the first part is incorrect. Suppose that both triangles are in the first quadrant (both coordinates positive). Then all nine points have positive coordinate and their convex hull doesn't contain 0,0
7th Nov 2018, 6:13 PM
michal
+ 2
The simplest algorithm to check collision seems to be: for each pair of edges, one edge from the first triangle, second frpm the other, find if they intersect. If any pair intersects, there is a collision. Otherwise not, but it still can be the case that one triangle is whole within the other.
7th Nov 2018, 8:38 PM
michal
+ 1
michal I think she is asking whether there are libraries for all this work or not. Not asking the way how it can be solved🤔
7th Nov 2018, 5:55 PM
Roneel
Roneel - avatar
0
One thing I can't understand: Check if (0,0) is in (1,2,),(3,3),…,(5,0) . Why need for two triangle a and b? How there collision is related to finding (0,0) thing? (I haven't opened wiki link yet) Initially I thought I am so much beginner for this(still am). So, I didn't thought to solve this one. But then I think I could have solved it hypothetically though I may not be able to implement code and I got to "collision between two triangles" not any convex hull stuff. Then I surfed 5-6 stack overflow questions and found great answers and codes. Main thing to cheer for me, my idea was probably the fastest way to check😎 Edit: now I opened wiki links. I think I missed the word 'lets say'😁 so, this is well beyond my range.
7th Nov 2018, 6:38 PM
Roneel
Roneel - avatar
0
I have not really read any of the other answers, but here's mine : I highly recommend using tkinter to make graphical programs on python. There is a special keyword object.x/y which can be used to detect collision.
7th Nov 2018, 8:29 PM
Eragon1980
Eragon1980 - avatar