【solved】Help with Polygon Clipping

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Alexar
Party member
Posts: 174
Joined: Thu Feb 05, 2015 1:57 am
Location: Chengdu,China

【solved】Help with Polygon Clipping

Post by Alexar »

Hi all,
I need the method of polygon clipping. but I didn't find any lib for this. what I want is to do operation Boolean of two polygons. "and","or","not",
I try to translate https://github.com/tmpvar/2d-polygon-boolean into lua. but always get errors. Can you help me with this? or correct my code translated.
polygon.rar
(72.34 KiB) Downloaded 68 times
Thank you!
Last edited by Alexar on Wed Sep 14, 2016 6:16 am, edited 1 time in total.
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: Help with Polygon Clipping

Post by airstruck »

I know we spoke about this earlier, but I forgot to mention this ticket in the issue tracker:

https://bitbucket.org/rude/love/issues/ ... n-lovemath

I would use something like this, I'm sure you would too; maybe it could be added if enough people would use it.

About the code you posted, something is wrong with table.reverse, it creates a new reversed table but never returns it, and the code that calls table.reverse treats it like an in-place operation (doesn't use return value). Haven't looked at the rest closely yet.
User avatar
Alexar
Party member
Posts: 174
Joined: Thu Feb 05, 2015 1:57 am
Location: Chengdu,China

Re: Help with Polygon Clipping

Post by Alexar »

airstruck wrote:About the code you posted, something is wrong with table.reverse, it creates a new reversed table but never returns it, and the code that calls table.reverse treats it like an in-place operation (doesn't use return value). Haven't looked at the rest closely yet.
please help me with the rest, i am nearly mad on this method. :cry:
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: Help with Polygon Clipping

Post by pgimeno »

Are the polygons convex?

The intersection of two convex polygons is a convex polygon. The union, rarely. The "not" operation I don't understand, unless you mean subtraction.

There are efficient algorithms to intersect convex polygons. The article the code you've posted is based on deals with arbitrary polygons, even self-intersecting.
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: Help with Polygon Clipping

Post by airstruck »

Alexar wrote:please help me with the rest, i am nearly mad on this method. :cry:
I wish I could help but I really have no experience with this stuff :(

I'd have to port the whole thing to Lua like you're doing, I can't really tell if anything's wrong by looking at it.
User avatar
Alexar
Party member
Posts: 174
Joined: Thu Feb 05, 2015 1:57 am
Location: Chengdu,China

Re: 【solved】Help with Polygon Clipping

Post by Alexar »

User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: 【solved】Help with Polygon Clipping

Post by airstruck »

Awesome, can't wait to try it!
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 79 guests