Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polygon subtraction #2

Open
Sajdkick opened this issue Jul 14, 2018 · 5 comments
Open

Polygon subtraction #2

Sajdkick opened this issue Jul 14, 2018 · 5 comments

Comments

@Sajdkick
Copy link

Sajdkick commented Jul 14, 2018

Great stuff you got here! Just one question, you mention in the description that you can perform subtraction. Is it possible to subtract one polygon from another as shown in the picture below? So far i have only managed to do an XOR.
image

Thanks!

@Sajdkick Sajdkick changed the title Polygon subtracting Polygon subtraction Jul 14, 2018
@Geri-Borbas
Copy link
Owner

Geri-Borbas commented Jul 15, 2018 via email

@Sajdkick
Copy link
Author

Awesome, thanks for the quick reply!

All i had to do was to change this:
clipper.Execute(ClipType.ctUnion, unionPaths);

Into:
clipper.Execute(ClipType.ctDifference, unionPaths);

So if you wanted a general function for doing all these kinds of operations you could change the function public Polygon UnionPolygon() into public Polygon BooleanOperation(ClipType clipType)

Super simple, thanks again!

@Geri-Borbas
Copy link
Owner

Geri-Borbas commented Jul 15, 2018

Boolean operations are done using Clipper, a great open source freeware library for clipping and offsetting lines and polygons.

So far I only incorporated union, but you can easily extend the library to make extension methods doing different types of clipping operations. See ClipType for the actual Clipper documentation.

In this library, only ClipType.ctUnion is implemented so far. See Polygon.cs#L626.

@Geri-Borbas
Copy link
Owner

Geri-Borbas commented Jul 15, 2018

You can nicely arrange the extensions into an extension class like below.

using System;
using UnityEngine;


namespace EPPZ.Geometry
{


	public static class Polygon_Extensions
	{

                public Polygon IntersectionPolygon(this Polygon _this)
		{ ... }

                public Polygon DifferencePolygon(this Polygon _this)
		{ ... }

                public Polygon XORPolygon(this Polygon _this)
		{ ... }
	}
}

@kamrankhorasani
Copy link

i can't open example scene in unity 2018.3.6.
is there any thing to do before importing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants