schteppe / poly-decomp.js Goto Github PK
View Code? Open in Web Editor NEWDecompose 2D polygons into convex pieces.
Home Page: http://schteppe.github.io/poly-decomp.js/
License: MIT License
Decompose 2D polygons into convex pieces.
Home Page: http://schteppe.github.io/poly-decomp.js/
License: MIT License
Hi,
Some of the dependencies in package.json are quite old. Would it be possible to update to the newest versions?
Thank you for making this! Really helpful.
I'm using this with box2Dweb and I can get in situations where a polygon is self overlapping.
The decomp doesn't work with those. (Correct me if I'm wrong)
Do you know of a good solution for those cases?
To clarify, cases like these:
http://schteppe.github.io/poly-decomp.js/#path=577,609/625,593/631,645/604,602/581,557
http://schteppe.github.io/poly-decomp.js/#path=709,486/759,466/809,453/859,454/877,501/882,552/892,604/841,590/789,581/807,533/860,526/910,523/885,478/837,493/787,500/739,517
http://schteppe.github.io/poly-decomp.js/#path=883,326/935,325/990,323/1043,329/1046,379/1022,423/987,465/951,500/914,459/896,412/939,385/954,433/905,445/855,439/815,407
Thanks,
Jakob
In the online demo : http://schteppe.github.io/poly-decomp.js
when I uncheck "quickDecomp" , it can't run 'Peaks' .
The program will fall in deadlock
I want to use this repo to decomp a polygon with some holes ,
Could support it ?
Thanks
Currently it seems like the duplicate point [0,0] is not removed using removeCollinearPoints().
var data = [[0,0] , [0, -32] , [32, -64] , [64, -64] , [64,-96], [128,-96], [160,-128], [192,-128], [192,-96], [160,-64], [96,-64], [96,-32], [32,-32], [32,0], [0,0]];
hi thank's for you're great library i've got a question:
before decomposing a polygon in convex area i need to be sure that the points are in counter clockwise order using makeCCW () ?
and another questione: your decomp() function use that https://mpen.ca/406/keil it's true?
or something that makes it pathologically slow:
var concavePolygon =
[
[8.506701527949408, -5.644336556342278],
[8.381300121570893, -6.808676269682801],
[8.593308091786604, -7.307181903188466],
[10.420617533158147, -8.765859313039982],
[12.179298508455794, -9.54478382111818],
[12.392753632051935, -9.69259565842458],
[12.550103732288154, -9.971123388711604],
[13.116831259916689, -9.77308275919102],
[13.779683167845178, -10.32537253615963],
[13.994641104567053, -10.27158839269665],
[14.319193079974866, -9.927854007472051],
[14.409695825989765, -9.66248864141151],
[14.326094888404041, -9.149005145166157],
[14.397728980729553, -8.898239412983857],
[14.976701652345255, -8.01431857421041],
[15.161213708335236, -7.232141297967173],
[15.015774793613819, -6.81465228562316],
[13.805676268945536, -6.390203862315247],
[13.60647004017097, -6.202602349251247],
[13.349711634656268, -5.892076457665607],
[13.16458732146697, -5.348712881724059],
[12.895862070692056, -5.410061602323695],
[12.563573390674136, -5.7334472750466015],
[11.891760263736687, -5.843890101286925],
[11.274549347033426, -5.724899302880986],
[10.587819408329743, -5.372616945485351],
[9.387516998851206, -5.387519162447352],
[8.653030998597279, -5.029260789111358],
[8.52673903629231, -5.404993335640029]
];
decomp.makeCCW(concavePolygon);
var convexPolygons = decomp.decomp(concavePolygon); <-- this hangs the page
// var convexPolygons = decomp.quickDecomp(concavePolygon); <-- this is OK
Hello, I have a special requirement on my end that when calling the quickDecomp method, the segmented polygon should contain at least 4 vertices, so I don't want triangles to appear. What should I do?
Hi,
I use matter-js, which uses poly-decomp for decomposition of concave shapes. And from what I can tell they use it correctly.
As I understand decomposition should work if isSimple() returns true, correct me if I'm wrong.
my stringified dataset:
[[0,-79.44508550870114],[10,-99.0834989573238],[20,-128.29964750979318],[30,-185.09029800617753],[40,-134.0195021932894],[50,-139.5227157326003],[60,-215.58025321809043],[70,-6.122609059449391],[80,-236.07719042816427],[90,-226.24259910699942],[100,-238.8041580583293],[110,-140.12907455932222],[120,-52.898053692856664],[130,-116.1611158499016],[140,-182.81279630844563],[150,-57.05993977865975],[160,-93.0145040380496],[170,-234.66429450441535],[180,-36.42968890750706],[190,-163.89528934984702],[200,0],[0,0]]
and result as returned by poly-decomp:
[[[40,-134.0195021932894],[10,-99.0834989573238],[20,-128.29964750979318]],[[20,-128.29964750979318],[30,-185.09029800617753],[40,-134.0195021932894]],[[50,-139.5227157326003],[60,-215.58025321809043],[70,-6.122609059449391]],[[118.85126572145955,0],[0,0],[0,-79.44508550870114],[10,-99.0834989573238],[40,-134.0195021932894],[50,-139.5227157326003],[110,-140.12907455932222],[120,-52.898053692856664]],[[130,-116.1611158499016],[140,-182.81279630844563],[150,-57.05993977865975]],[[160,-93.0145040380496],[170,-234.66429450441535],[180,-36.42968890750706]],[[180,-36.42968890750706],[190,-163.89528934984702],[200,0],[185.00906723012366,0]],[[185.00906723012366,0],[118.85126572145955,0],[120,-52.898053692856664],[130,-116.1611158499016],[160,-93.0145040380496],[180,-36.42968890750706]]]
The error is apparent as the vector [100, -238.8041580583293] does not show up in the result...
I also added images that showcase how it should, and how it actually does, look like. (for this I simply cut the shape into stripes)
I am finding that some hull shapes will return an empty array (for both polygonDecomp(a) and polygonQuickDecomp(a) ). Here's an example - when plotted in Excel these points make a simple hull shape:
[[1100,300],[300,1100],[300,3100],[1300,3700],[3100,3800],[3700,3200],[3700,2300],[1800,300],[1200,300]]
Hi, I'm currently working on a Pinball game.
I found a pinball demo at codepen which renders the "DOME" path properly.
The issue is when I use the latest version of 'poly-decomp', Only half part of the "DOME" is displayed.
Updated codepen demo with the latest build giving unexpected results.
Please let me know if there is any breaking change is added in latest build or do I need to update the provided path for correct rendering.
Thanks!
Thanks for this library but If I pass a simple concave shape array then it is simply returned as if it's a convex shape (this is easily repeatable with other simple concave shapes). For example:
[[0.2, 0.2], [0.5, -0.5], [0.5, 0.5], [-0.5, 0.5]]
Initializing lowerIndex at 0 is unsafe and causes some Edge Case miscalculations and bizarre artifacts. The 2nd code snippet shows where lowerIndex(0) could equal (upperIndex+1)%poly.length if upperIndex is poly.length-1. Even when lowerIndex was never actually calculated.
This code is from polygonQuickDecomp
var upperInt = [0, 0], lowerInt = [0, 0], p = [0, 0]; // Points
var upperDist = 0, lowerDist = 0, d = 0, closestDist = 0; // scalars
var upperIndex = 0, lowerIndex = 0, closestIndex = 0;
if (lowerIndex === (upperIndex + 1) % polygon.length) {
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.