come / csg2d.js Goto Github PK
View Code? Open in Web Editor NEWA 2D port of CSG 3D library
Home Page: http://come.github.io/csg2d.js/
License: MIT License
A 2D port of CSG 3D library
Home Page: http://come.github.io/csg2d.js/
License: MIT License
Hi!
I was so happy to find this csg2d because I have to merge shape parts of a way (osm.org)
But I got creasy results and made a small test with 2 cycles: Depending on the numbers,
csg2d gets mad. The points seem to be ok, but in wrong order.
There should be only on shape as result, if the parts overlap, right? But I get more.
And the merge of the 2 cycles shows a big gap.
If I check the points, [2] is the same as [0] and to much.
If I only use 0 to 74, the shape is ok, with 75 I get an error:
THREE.ShapeUtils: Unable to triangulate polygon! in triangulate()
There are quite a view "to much points", some so cross,
they disable triangulation
This is the relevant part of the Code:
function SinCos(a,r){
return [ Math.sin(a)*r
, Math.cos(a)*r ];
}
function CircleCSG(radius,segments,x,y){
var polygon = [];
var max = 360
for(var a=0; a<g(max) ; a+= g(max/segments) )
{ var sc = SinCos(a,radius);
polygon.push( [ x+sc[0] , y+sc[1] ] );
}
var ret = CSG.fromPolygons([polygon])
return ret
}
a=42 // 41 ok 42 gap!
r=6
csg1 = CircleCSG(r,a,0,0)
csg2 = CircleCSG(r,a,r,0)
csg2 = csg2.intersect(csg1) // <==== ???
polys = csg2.toPolygons()
This is the comlete code
https://dl.dropboxusercontent.com/u/24005683/template_csg.html
This my result
https://dl.dropboxusercontent.com/u/24005683/shapes2.png
This is the detail view with the wrong point order visible
https://dl.dropboxusercontent.com/u/24005683/shapes3.png
The resulting point list:
0 6 6
1 6.894253597057046 5.932984957350771
2 6 6
3 7.768531046465425 5.733436834716844
4 8.603302434705348 5.405813207414515
5 8.703900614584843 5.347732821181102
6 9.37992034838173 4.957432645895969
7 10.081036426625516 4.398311230978958
8 10.690988894808179 3.740938811152403
9 10.726511876399575 3.688836166572312
10 11.196152422706632 3.0000000000000018
11 11.585242491865225 2.192046146198372
12 11.694521377142236 1.8377727013774756
13 11.849567473090941 1.3351256037378894
14 11.983222783087081 0.448380561518548
15 11.983222783087081 -0.0096863307009287
16 11.983222783087081 -0.4483805615185416
17 11.849567473090943 -1.3351256037378822
18 11.735253303081837 -1.7057230407295563
19 11.585242491865227 -2.192046146198366
20 11.196152422706634 -2.9999999999999964
21 11.0900558150185 -3.1556151424762957
22 10.69098889480818 -3.7409388111523985
23 10.172804820474946 -4.299408424161673
24 10.081036426625518 -4.3983112309789565
25 9.379920348381733 -4.9574326458959685
26 9.104755961391012 -5.116298878796459
27 8.603302434705348 -5.405813207414514
28 8.001702222483125 -5.641923891717757
29 7.768531046465425 -5.733436834716844
30 6.943369192781921 -5.921774643135784
31 6.8942535970570455 -5.932984957350771
32 5.999999999999998 -6
33 5.983222783087081 -5.998742721404024
34 5.1559842286792685 -5.936749761926793
35 5.10574640294295 -5.932984957350771
36 4.4756750965770795 -5.789175293272284
37 4.231468953534571 -5.733436834716843
38 3.935700142028447 -5.617356130186653
39 3.5222903508414976 -5.45510474344885
40 2.6033024347053493 -5.405813207414514
41 1.768531046465425 -5.733436834716844
42 0.8942535970570455 -5.932984957350771
43 -1.92974717961e-15 -6
44 -0.894253597057049 -5.932984957350771
45 -1.768531046465429 -5.733436834716843
46 -2.603302434705353 -5.405813207414512
47 -2.703900614584839 -5.347732821181104
48 -3.379920348381736 -4.957432645895966
49 -4.081036426625521 -4.398311230978953
50 -4.690988894808181 -3.7409388111523985
51 -4.72651187639958 -3.6888361665723037
52 -5.196152422706633 -2.9999999999999982
53 -5.585242491865225 -2.1920461461983693
54 -5.694521377142242 -1.8377727013774536
55 -5.849567473090941 -1.3351256037378876
56 -5.983222783087081 -0.4483805615185483
57 -5.983222783087081 0.0096863307009388
58 -5.983222783087081 0.4483805615185409
59 -5.849567473090943 1.33512560373788
60 -5.7352533030818345 1.7057230407295665
61 -5.585242491865229 2.1920461461983627
62 -5.196152422706637 2.999999999999991
63 -5.090055815018497 3.1556151424763024
64 -4.690988894808186 3.7409388111523914
65 -4.17280482047494 4.299408424161681
66 -4.081036426625526 4.3983112309789485
67 -3.379920348381745 4.9574326458959606
68 -3.104755961391002 5.116298878796465
69 -2.6033024347053644 5.405813207414507
70 -2.001702222483127 5.641923891717758
71 -1.7685310464654436 5.733436834716839
72 -0.9433691927819224 5.921774643135785
73 0.01677721691291900 5.998742721404024
74 0 6
75 -0.8942535970570675 5.932984957350768
76 -2.278585823177e-14 6
77 0.8440157713207327 5.936749761926793
78 0.8942535970570464 5.932984957350771
79 1.5243249034229187 5.789175293272284
80 1.768531046465425 5.733436834716844
81 2.0642998579715477 5.617356130186654
82 2.4777096491585016 5.455104743448852
83 2.6033024347053484 5.405813207414515
84 2.7664110551033425 5.311642401520585
85 2.939170924336701 5.211899444513540
86 3.3966975652946356 5.405813207414507
87 3.3420859745374134 5.374283190789951
88 3.0756233350074944 5.220440914128373
89 3 5.176779761304779
90 4.123337939822973 5.690998539112623
91 4.231468953534557 5.733436834716839
92 5.105746402942932 5.932984957350768
93 5.999999999999977 6
There's a line console.log("FOOO");
in the released package on NPM. Could you remove it?
Do you support the circle?
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.