Jump to content


Photo

Collision Polygon...


  • Please log in to reply
16 replies to this topic

#1 FatalSleep

FatalSleep

    Dominus Veroth

  • GMC Member
  • 1218 posts
  • Version:GM:Studio

Posted 19 September 2012 - 07:03 PM

So I have a few collision with point functions... what they do is check if a point: x1,y1 are within a figure: triangle, circle, rectangle, and quadrilateral.
However I did not make the triangle and quadrilateral scripts.

Here they are:
Spoiler

I am only presenting these because I did not make them, and I am guessing the general idea for a collision
with polygon code would be similar in the way these are done. So how exactly would I code this problem?

Edited by FatalSleep, 20 September 2012 - 10:01 AM.

  • 1

#2 Experimenator

Experimenator

    Java Developer

  • GMC Member
  • 357 posts
  • Version:GM8

Posted 20 September 2012 - 11:27 AM

The only idea I can think of is to check whether every point of the polygon is in another polygon, and again but from 2nd to 1st polygon.

Scripts:
Spoiler

I haven't tested it, but I suppose it would work.
I can't guarantee the best performance but You can also try checking if every side of the polygon intersects another polygon which might be faster.

I would suggest you to read this: http://www.mathopenr...coordintro.html
So you can get a better understanding how those stuff work.

EDIT: Someone moved this topic to 3D Game Techniques. idk why but this is pure 2D

Edited by Experimenator, 20 September 2012 - 11:31 AM.

  • 0

#3 FatalSleep

FatalSleep

    Dominus Veroth

  • GMC Member
  • 1218 posts
  • Version:GM:Studio

Posted 20 September 2012 - 02:38 PM

Well after editing the other scripts I cam up with this 5 sided polygon:
Spoiler

So I guess I understand this script, so I'll see if I can convert it to a polygon that can have an infinite number of sides using
a for loop.

Edited by FatalSleep, 20 September 2012 - 02:38 PM.

  • 0

#4 Experimenator

Experimenator

    Java Developer

  • GMC Member
  • 357 posts
  • Version:GM8

Posted 20 September 2012 - 02:59 PM

Now I don't understand what are you trying.
Why are you making your own point_in_polygon when that script already exists?
(look at the first script in my 1st post)
And also, are you looking for polygon-polygon or point-polygon collision?
  • 0

#5 FatalSleep

FatalSleep

    Dominus Veroth

  • GMC Member
  • 1218 posts
  • Version:GM:Studio

Posted 20 September 2012 - 08:06 PM

This is because using an entire data structure for one polygon is extremely inefficient.
Why would I use data structures when it can be done without it?

Anyways I've made multiple scripts for different sided polygons: pentagon, hexagon, heptagon.
All without data structures.
  • -1

#6 Experimenator

Experimenator

    Java Developer

  • GMC Member
  • 357 posts
  • Version:GM8

Posted 21 September 2012 - 11:50 AM

You know, a Personal Computer usually has 2GB memory and 1.6GHz Processor which means it can do a billion operations in a second. a tiny Data Structure, like this, (+-32 elements) is so tiny that it will NEVER affect the performance of the program. My own computer, weaker than the standard, can do 30000 elementAdds without any performance problem.
And you think those minute 10-20 elements
DataStructures are not performance-consumers. They are made to kill that.

Also it is even more inefficient using scripts because whenever you call a script, all 16 arguments have to be rewritten to use a script. And you cannot do n-sided because Game Maker can have 16 arguments at max.

If you were going to say that on http://stackoverflow.com/ you would have got tones of down votes because they absolutely hate when people are concentrating to maximum performance instead of focusing on the main issues.
Unfortunately, this isn't stackoverflow.

Why did you ask the question at all when you don't want to hear the answers, and replying how you are able to create those by yourself?

Edited by Experimenator, 21 September 2012 - 11:54 AM.

  • -2

#7 FatalSleep

FatalSleep

    Dominus Veroth

  • GMC Member
  • 1218 posts
  • Version:GM:Studio

Posted 21 September 2012 - 01:35 PM

A personal computer can do that. However Game Maker cannot, so if I say had a full fledged game with particles and 3d and data structure I'd have to be worried about performance so I don't drop the games fps and make the game unplayable. So why would I waste extra memory to preform an action that I can do in about 1/4 of that extra memory. Its not a matter of maximum performance, its a matter of being efficient and concise! Besides here I am focusing on efficiency and the main issue itself not only on maximum performance.

The only reason I said I could do it is because I realize a pattern. A pattern in the scripts allowing me to easily alter the scripts to make larger polygons. I didn't realize this until after you posted your scripts. I am sorry to have caused you trouble having you present those scripts and then me rejecting them. However I though it would be better if I found an easier way to create polygon collisions so as to where I could understand how those collisions were handled.

In a way you helped me quite a bit. I disliked how your scripts were handling those collisions so that pushed me even further into trying to figure it out myself. See I am a person that likes to learn. So if I can take a script as small as the ones I had and be able to expand them to make them more useful then that's what I am going to do. For me this is all a learning experience so I want to be able to do things myself to make myself a better programmer. If I simply just took your scripts and accepted them I wouldn't have learned anything since those scripts already can have as large of a size of polygon as I wanted.

Edited by FatalSleep, 21 September 2012 - 01:37 PM.

  • 0

#8 Experimenator

Experimenator

    Java Developer

  • GMC Member
  • 357 posts
  • Version:GM8

Posted 21 September 2012 - 02:17 PM

If you want to learn I already have said, read this: http://www.mathopenr...coordintro.html
Afterwards you'll be able to do everything with geometry, even create your own algorithms and scripts.

You should stop being afraid of data structures. If you would have seen how they are made and how they internally I believe you would too agree that they are very efficient.
Try this script for example:
var ds,i;
ds = ds_list_create();
for (i=0;i<50000;i+=1)
   ds_list_add(ds,0);

I can guarantee that it won't last a second.
Unless you have more than 1000 elemnts ds_list will take almost none of CPU power.
There is nothing to "efficianate" there.

The point-polygon script uses even-odd rule which is widely use among those like algorithms.

Also, it isn't fair because, I +1 your original post before, and -1 one of your posts later which basecally means I gave you no change in reputation while you downvoted me.
All because I was trying to help you. -_-
  • 1

#9 FatalSleep

FatalSleep

    Dominus Veroth

  • GMC Member
  • 1218 posts
  • Version:GM:Studio

Posted 21 September 2012 - 03:15 PM

Haha. Well then. I am not afraid of data structures I know every well what they can do. Oh I have no trouble with geometry really, I just have trouble mixing the math I learn in with Game Maker.
Thats why i was manipulating the scripts I presented. Btw I think a ds_list can only have up to 32,000 entries. Posted Image

Anyways thanks for the help(I've learned quite a bit here). Posted Image

Edited by FatalSleep, 21 September 2012 - 03:16 PM.

  • 0

#10 Experimenator

Experimenator

    Java Developer

  • GMC Member
  • 357 posts
  • Version:GM8

Posted 21 September 2012 - 03:32 PM

Btw I think a ds_list can only have up to 32,000 entries.

They go all through the infinity :thumbsup:

Edited by Experimenator, 21 September 2012 - 03:32 PM.

  • 0

#11 FatalSleep

FatalSleep

    Dominus Veroth

  • GMC Member
  • 1218 posts
  • Version:GM:Studio

Posted 21 September 2012 - 05:12 PM

Btw I think a ds_list can only have up to 32,000 entries.

They go all through the infinity :thumbsup:


Heh, if they can make ds_lists do that, I wonder why they can't do that with arrays...
  • 0

#12 Experimenator

Experimenator

    Java Developer

  • GMC Member
  • 357 posts
  • Version:GM8

Posted 21 September 2012 - 05:41 PM

When I was making my own language it was very easy to make an array to contain any number and even a string.
just making a variable name string made like this "variableName+arrayValue+]" and you then you can make any array you want even multidimensional and infinite.

idk why can't it be done here. :unsure:
  • 0

#13 FatalSleep

FatalSleep

    Dominus Veroth

  • GMC Member
  • 1218 posts
  • Version:GM:Studio

Posted 21 September 2012 - 05:55 PM

Heh Game Maker is weak thats why. I can't wait till YoYo starts fixing all these small stupid things in Game Maker.
  • 0

#14 Experimenator

Experimenator

    Java Developer

  • GMC Member
  • 357 posts
  • Version:GM8

Posted 21 September 2012 - 06:01 PM

It is weak indeed. >_>
But maybe things are fixed up in studio.
I don't have it so idk.
  • 0

#15 brac37

brac37

    GMC Member

  • GMC Member
  • 765 posts
  • Version:GM7

Posted 21 September 2012 - 07:09 PM

The red cross is made of two overlapping red rectangles without polygon points in the other polygon.

Edit: here is an algorithm.
http://content.gpwik...lygon_Collision
Edit edit: only convex polygons.

With non-convex polygons, you can test whether there are crossing edges. If this is the case, then there is intersection.

If not, then take an arbitrary point of polygon 1 and test whether is in polygon 2. If this is the case, then there is intersection.

If not, then take an arbitrary point of polygon 2 and test whether is in polygon 1. If this is the case, then there is intersection. If this is not the case, then there is no intersection.

You can test whether a point is inside a polygon by making an artificial edge from the point to a very far point, and compute the parity of the number of intersections with edges of the polygon, see
http://paulbourke.ne...try/insidepoly/

Edited by brac37, 21 September 2012 - 08:14 PM.

  • 0

#16 gmx0

gmx0

    The Messenger

  • GMC Member
  • 1182 posts
  • Version:GM6

Posted 22 November 2012 - 05:34 PM

If hasn't been done or said already, all polygons can be split into triangles, so just repeat the triangle collision function for three different points until it returns true?
  • 0

#17 Gamer3D

Gamer3D

    Human* me = this;

  • GMC Member
  • 1589 posts
  • Version:GM8.1

Posted 22 November 2012 - 08:26 PM

If hasn't been done or said already, all polygons can be split into triangles, so just repeat the triangle collision function for three different points until it returns true?

That would be inefficient, and it would only work properly for convex polygons.

One method is to count the number of line segments intersecting with a ray going from x,y to the right (or in any other direction, so long as it's consistent). If the number is even, you're outside. If odd, you're inside.
Note that you need to be careful not to count vertexes twice.

Also, you probably didn't need to revive a post from September....
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users