1 | ## Classes
|
2 |
|
3 | <dl>
|
4 | <dt><a href="#CAG">CAG</a></dt>
|
5 | <dd></dd>
|
6 | <dt><a href="#CSG">CSG</a></dt>
|
7 | <dd></dd>
|
8 | <dt><a href="#Path2D">Path2D</a></dt>
|
9 | <dd></dd>
|
10 | <dt><a href="#Polygon">Polygon</a></dt>
|
11 | <dd></dd>
|
12 | <dt><a href="#Vector2D">Vector2D</a></dt>
|
13 | <dd></dd>
|
14 | <dt><a href="#Vector3D">Vector3D</a></dt>
|
15 | <dd></dd>
|
16 | </dl>
|
17 |
|
18 | ## Constants
|
19 |
|
20 | <dl>
|
21 | <dt><a href="#defaultResolution2D">defaultResolution2D</a></dt>
|
22 | <dd><p>Number of polygons per 360 degree revolution for 2D objects.</p>
|
23 | </dd>
|
24 | <dt><a href="#defaultResolution3D">defaultResolution3D</a></dt>
|
25 | <dd><p>Number of polygons per 360 degree revolution for 3D objects.</p>
|
26 | </dd>
|
27 | <dt><a href="#EPS">EPS</a></dt>
|
28 | <dd><p>Epsilon used during determination of near zero distances.</p>
|
29 | </dd>
|
30 | <dt><a href="#angleEPS">angleEPS</a></dt>
|
31 | <dd><p>Epsilon used during determination of near zero areas.</p>
|
32 | </dd>
|
33 | <dt><a href="#areaEPS">areaEPS</a></dt>
|
34 | <dd><p>Epsilon used during determination of near zero areas.
|
35 | This is the minimal area of a minimal polygon.</p>
|
36 | </dd>
|
37 | </dl>
|
38 |
|
39 | ## Functions
|
40 |
|
41 | <dl>
|
42 | <dt><a href="#center">center(object(s), options)</a></dt>
|
43 | <dd><p>NOTE: this is not functional YET !!
|
44 | centers the given object(s) on the given axis</p>
|
45 | </dd>
|
46 | <dt><a href="#clone">clone(obj)</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
47 | <dd><p>clone the given object</p>
|
48 | </dd>
|
49 | <dt><a href="#css2rgb">css2rgb(String)</a> ⇒</dt>
|
50 | <dd><p>Converts an CSS color name to RGB color.</p>
|
51 | </dd>
|
52 | <dt><a href="#color">color(color, objects)</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
53 | <dd><p>apply the given color to the input object(s)</p>
|
54 | </dd>
|
55 | <dt><a href="#rgb2hsl">rgb2hsl(Number, Number, Number)</a> ⇒</dt>
|
56 | <dd><p>Converts an RGB color value to HSL. Conversion formula
|
57 | adapted from <a href="http://en.wikipedia.org/wiki/HSL_color_space">http://en.wikipedia.org/wiki/HSL_color_space</a>.
|
58 | Assumes r, g, and b are contained in the set [0, 1] and
|
59 | returns h, s, and l in the set [0, 1].</p>
|
60 | </dd>
|
61 | <dt><a href="#hsl2rgb">hsl2rgb(Number, Number, Number)</a> ⇒</dt>
|
62 | <dd><p>Converts an HSL color value to RGB. Conversion formula
|
63 | adapted from <a href="http://en.wikipedia.org/wiki/HSL_color_space">http://en.wikipedia.org/wiki/HSL_color_space</a>.
|
64 | Assumes h, s, and l are contained in the set [0, 1] and
|
65 | returns r, g, and b in the set [0, 1].</p>
|
66 | </dd>
|
67 | <dt><a href="#rgb2hsv">rgb2hsv(Number, Number, Number)</a> ⇒</dt>
|
68 | <dd><p>Converts an RGB color value to HSV. Conversion formula
|
69 | adapted from <a href="http://en.wikipedia.org/wiki/HSV_color_space">http://en.wikipedia.org/wiki/HSV_color_space</a>.
|
70 | Assumes r, g, and b are contained in the set [0, 1] and
|
71 | returns h, s, and v in the set [0, 1].</p>
|
72 | </dd>
|
73 | <dt><a href="#hsv2rgb">hsv2rgb(Number, Number, Number)</a> ⇒</dt>
|
74 | <dd><p>Converts an HSV color value to RGB. Conversion formula
|
75 | adapted from <a href="http://en.wikipedia.org/wiki/HSV_color_space">http://en.wikipedia.org/wiki/HSV_color_space</a>.
|
76 | Assumes h, s, and v are contained in the set [0, 1] and
|
77 | returns r, g, and b in the set [0, 1].</p>
|
78 | </dd>
|
79 | <dt><a href="#html2rgb">html2rgb()</a></dt>
|
80 | <dd><p>Converts a HTML5 color value (string) to RGB values
|
81 | See the color input type of HTML5 forms
|
82 | Conversion formula:</p>
|
83 | <ul>
|
84 | <li>split the string; "#RRGGBB" into RGB components</li>
|
85 | <li>convert the HEX value into RGB values</li>
|
86 | </ul>
|
87 | </dd>
|
88 | <dt><a href="#rgb2html">rgb2html()</a></dt>
|
89 | <dd><p>Converts RGB color value to HTML5 color value (string)
|
90 | Conversion forumla:</p>
|
91 | <ul>
|
92 | <li>convert R, G, B into HEX strings</li>
|
93 | <li>return HTML formatted string "#RRGGBB"</li>
|
94 | </ul>
|
95 | </dd>
|
96 | <dt><a href="#union">union(objects)</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
97 | <dd><p>union/ combine the given shapes</p>
|
98 | </dd>
|
99 | <dt><a href="#difference">difference(objects)</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
100 | <dd><p>difference/ subtraction of the given shapes ie:
|
101 | cut out C From B From A ie : a - b - c etc</p>
|
102 | </dd>
|
103 | <dt><a href="#intersection">intersection(objects)</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
104 | <dd><p>intersection of the given shapes: ie keep only the common parts between the given shapes</p>
|
105 | </dd>
|
106 | <dt><a href="#overCutInsideCorners">overCutInsideCorners(_cag, cutterradius)</a> ⇒ <code><a href="#CAG">CAG</a></code></dt>
|
107 | <dd><p>cag = cag.overCutInsideCorners(cutterradius);
|
108 | Using a CNC router it's impossible to cut out a true sharp inside corner. The inside corner
|
109 | will be rounded due to the radius of the cutter. This function compensates for this by creating
|
110 | an extra cutout at each inner corner so that the actual cut out shape will be at least as large
|
111 | as needed.</p>
|
112 | </dd>
|
113 | <dt><a href="#sectionCut">sectionCut(csg, orthobasis)</a></dt>
|
114 | <dd><p>cuts a csg along a orthobasis</p>
|
115 | </dd>
|
116 | <dt><a href="#cutByPlane">cutByPlane(plane)</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
117 | <dd><p>Cut the solid by a plane. Returns the solid on the back side of the plane</p>
|
118 | </dd>
|
119 | <dt><a href="#expandedShellOfCCSG">expandedShellOfCCSG(radius, resolution, unionWithThis)</a></dt>
|
120 | <dd><p>Create the expanded shell of the solid:
|
121 | All faces are extruded to get a thickness of 2*radius
|
122 | Cylinders are constructed around every side
|
123 | Spheres are placed on every vertex
|
124 | unionWithThis: if true, the resulting solid will be united with 'this' solid;
|
125 | the result is a true expansion of the solid
|
126 | If false, returns only the shell</p>
|
127 | </dd>
|
128 | <dt><a href="#extrudeInOrthonormalBasis">extrudeInOrthonormalBasis(cag, orthonormalbasis, depth, [options])</a></dt>
|
129 | <dd><p>extrude the CAG in a certain plane.
|
130 | Giving just a plane is not enough, multiple different extrusions in the same plane would be possible
|
131 | by rotating around the plane's origin. An additional right-hand vector should be specified as well,
|
132 | and this is exactly a OrthoNormalBasis.</p>
|
133 | </dd>
|
134 | <dt><a href="#extrudeInPlane">extrudeInPlane(cag, axis1, axis2, depth, [options])</a></dt>
|
135 | <dd><p>Extrude in a standard cartesian plane, specified by two axis identifiers. Each identifier can be
|
136 | one of ["X","Y","Z","-X","-Y","-Z"]
|
137 | The 2d x axis will map to the first given 3D axis, the 2d y axis will map to the second.
|
138 | See OrthoNormalBasis.GetCartesian for details.</p>
|
139 | </dd>
|
140 | <dt><a href="#extrude">extrude(cag, [options])</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
141 | <dd><p>linear extrusion of 2D shape, with optional twist</p>
|
142 | </dd>
|
143 | <dt><a href="#rotateExtrude">rotateExtrude(options)</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
144 | <dd><p>Extrude to into a 3D solid by rotating the origin around the Y axis.
|
145 | (and turning everything into XY plane)</p>
|
146 | </dd>
|
147 | <dt><a href="#linear_extrude">linear_extrude([options], baseShape)</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
148 | <dd><p>linear extrusion of the input 2d shape</p>
|
149 | </dd>
|
150 | <dt><a href="#rotate_extrude">rotate_extrude([options], baseShape)</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
151 | <dd><p>rotate extrusion / revolve of the given 2d shape</p>
|
152 | </dd>
|
153 | <dt><a href="#rectangular_extrude">rectangular_extrude(basePoints, [options])</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
154 | <dd><p>rectangular extrusion of the given array of points</p>
|
155 | </dd>
|
156 | <dt><a href="#translate">translate(vector, ...objects)</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
157 | <dd><p>translate an object in 2D/3D space</p>
|
158 | </dd>
|
159 | <dt><a href="#scale">scale(scale, ...objects)</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
160 | <dd><p>scale an object in 2D/3D space</p>
|
161 | </dd>
|
162 | <dt><a href="#rotate">rotate(rotation, objects)</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
163 | <dd><p>rotate an object in 2D/3D space</p>
|
164 | </dd>
|
165 | <dt><a href="#transform">transform(matrix, ...objects)</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
166 | <dd><p>apply the given matrix transform to the given objects</p>
|
167 | </dd>
|
168 | <dt><a href="#center">center(axis, ...objects)</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
169 | <dd><p>center an object in 2D/3D space</p>
|
170 | </dd>
|
171 | <dt><a href="#mirror">mirror(vector, ...objects)</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
172 | <dd><p>mirror an object in 2D/3D space</p>
|
173 | </dd>
|
174 | <dt><a href="#expand">expand(radius, object)</a> ⇒ <code>CSG/CAG</code></dt>
|
175 | <dd><p>expand an object in 2D/3D space</p>
|
176 | </dd>
|
177 | <dt><a href="#contract">contract(radius, object)</a> ⇒ <code>CSG/CAG</code></dt>
|
178 | <dd><p>contract an object(s) in 2D/3D space</p>
|
179 | </dd>
|
180 | <dt><a href="#minkowski">minkowski(objects)</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
181 | <dd><p>create a minkowski sum of the given shapes</p>
|
182 | </dd>
|
183 | <dt><a href="#hull">hull(objects)</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
184 | <dd><p>create a convex hull of the given shapes</p>
|
185 | </dd>
|
186 | <dt><a href="#chain_hull">chain_hull(objects)</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
187 | <dd><p>create a chain hull of the given shapes
|
188 | Originally "Whosa whatsis" suggested "Chain Hull" ,
|
189 | as described at <a href="https://plus.google.com/u/0/105535247347788377245/posts/aZGXKFX1ACN">https://plus.google.com/u/0/105535247347788377245/posts/aZGXKFX1ACN</a>
|
190 | essentially hull A+B, B+C, C+D and then union those</p>
|
191 | </dd>
|
192 | <dt><a href="#square">square([options])</a> ⇒ <code><a href="#CAG">CAG</a></code></dt>
|
193 | <dd><p>Construct a square/rectangle</p>
|
194 | </dd>
|
195 | <dt><a href="#circle">circle([options])</a> ⇒ <code><a href="#CAG">CAG</a></code></dt>
|
196 | <dd><p>Construct a circle</p>
|
197 | </dd>
|
198 | <dt><a href="#polygon">polygon([options])</a> ⇒ <code><a href="#CAG">CAG</a></code></dt>
|
199 | <dd><p>Construct a polygon either from arrays of paths and points, or just arrays of points
|
200 | nested paths (multiple paths) and flat paths are supported</p>
|
201 | </dd>
|
202 | <dt><a href="#triangle">triangle()</a> ⇒ <code><a href="#CAG">CAG</a></code></dt>
|
203 | <dd><p>Construct a triangle</p>
|
204 | </dd>
|
205 | <dt><a href="#circle">circle([options])</a> ⇒ <code><a href="#CAG">CAG</a></code></dt>
|
206 | <dd><p>Construct a circle.</p>
|
207 | </dd>
|
208 | <dt><a href="#ellipse">ellipse([options])</a> ⇒ <code><a href="#CAG">CAG</a></code></dt>
|
209 | <dd><p>Construct an ellispe.</p>
|
210 | </dd>
|
211 | <dt><a href="#rectangle">rectangle([options])</a> ⇒ <code><a href="#CAG">CAG</a></code></dt>
|
212 | <dd><p>Construct a rectangle.</p>
|
213 | </dd>
|
214 | <dt><a href="#roundedRectangle">roundedRectangle([options])</a> ⇒ <code><a href="#CAG">CAG</a></code></dt>
|
215 | <dd><p>Construct a rounded rectangle.</p>
|
216 | </dd>
|
217 | <dt><a href="#cube">cube([options])</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
218 | <dd><p>Construct a cuboid</p>
|
219 | </dd>
|
220 | <dt><a href="#sphere">sphere([options])</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
221 | <dd><p>Construct a sphere</p>
|
222 | </dd>
|
223 | <dt><a href="#cylinder">cylinder([options])</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
224 | <dd><p>Construct a cylinder</p>
|
225 | </dd>
|
226 | <dt><a href="#torus">torus([options])</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
227 | <dd><p>Construct a torus</p>
|
228 | </dd>
|
229 | <dt><a href="#polyhedron">polyhedron([options])</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
230 | <dd><p>Construct a polyhedron from the given triangles/ polygons/points</p>
|
231 | </dd>
|
232 | <dt><a href="#cube">cube([options])</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
233 | <dd><p>Construct an axis-aligned solid cuboid.</p>
|
234 | </dd>
|
235 | <dt><a href="#sphere">sphere([options])</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
236 | <dd><p>Construct a solid sphere</p>
|
237 | </dd>
|
238 | <dt><a href="#cylinder">cylinder([options])</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
239 | <dd><p>Construct a solid cylinder.</p>
|
240 | </dd>
|
241 | <dt><a href="#roundedCylinder">roundedCylinder([options])</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
242 | <dd><p>Construct a cylinder with rounded ends.</p>
|
243 | </dd>
|
244 | <dt><a href="#cylinderElliptic">cylinderElliptic([options])</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
245 | <dd><p>Construct an elliptic cylinder.</p>
|
246 | </dd>
|
247 | <dt><a href="#roundedCube">roundedCube([options])</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
248 | <dd><p>Construct an axis-aligned solid rounded cuboid.</p>
|
249 | </dd>
|
250 | <dt><a href="#polyhedron">polyhedron([options])</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
251 | <dd><p>Create a polyhedron using Openscad style arguments.
|
252 | Define face vertices clockwise looking from outside.</p>
|
253 | </dd>
|
254 | <dt><a href="#solidFromSlices">solidFromSlices(options)</a></dt>
|
255 | <dd><p>Creates solid from slices (Polygon) by generating walls</p>
|
256 | </dd>
|
257 | <dt><a href="#_addWalls">_addWalls(walls, bottom, top)</a></dt>
|
258 | <dd></dd>
|
259 | <dt><a href="#vector_char">vector_char(x, y, char)</a> ⇒ <code>Object</code></dt>
|
260 | <dd><p>Construct a with, segments tupple from a character</p>
|
261 | </dd>
|
262 | <dt><a href="#vector_text">vector_text(x, y, string)</a> ⇒ <code>Array</code></dt>
|
263 | <dd><p>Construct an array of with, segments tupple from a string</p>
|
264 | </dd>
|
265 | <dt><a href="#fromSides">fromSides(sides)</a> ⇒ <code><a href="#CAG">CAG</a></code></dt>
|
266 | <dd><p>Construct a CAG from a list of <code>Side</code> instances.</p>
|
267 | </dd>
|
268 | <dt><a href="#fromPoints">fromPoints(points)</a> ⇒ <code><a href="#CAG">CAG</a></code></dt>
|
269 | <dd><p>Construct a CAG from a list of points (a polygon).
|
270 | The rotation direction of the points is not relevant.
|
271 | The points can define a convex or a concave polygon.
|
272 | The polygon must not self intersect.</p>
|
273 | </dd>
|
274 | <dt><a href="#fromObject">fromObject(obj)</a> ⇒ <code><a href="#CAG">CAG</a></code></dt>
|
275 | <dd><p>Reconstruct a CAG from an object with identical property names.</p>
|
276 | </dd>
|
277 | <dt><a href="#fromPointsNoCheck">fromPointsNoCheck(points)</a> ⇒ <code><a href="#CAG">CAG</a></code></dt>
|
278 | <dd><p>Construct a CAG from a list of points (a polygon).
|
279 | Like fromPoints() but does not check if the result is a valid polygon.
|
280 | The points MUST rotate counter clockwise.
|
281 | The points can define a convex or a concave polygon.
|
282 | The polygon must not self intersect.</p>
|
283 | </dd>
|
284 | <dt><a href="#fromPath2">fromPath2(Path2)</a> ⇒ <code><a href="#CAG">CAG</a></code></dt>
|
285 | <dd><p>Construct a CAG from a 2d-path (a closed sequence of points).
|
286 | Like fromPoints() but does not check if the result is a valid polygon.</p>
|
287 | </dd>
|
288 | <dt><a href="#fromCompactBinary">fromCompactBinary(bin)</a> ⇒ <code><a href="#CAG">CAG</a></code></dt>
|
289 | <dd><p>Reconstruct a CAG from the output of toCompactBinary().</p>
|
290 | </dd>
|
291 | <dt><a href="#fromPolygons">fromPolygons(polygons)</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
292 | <dd><p>Construct a CSG solid from a list of <code>Polygon</code> instances.</p>
|
293 | </dd>
|
294 | <dt><a href="#fromSlices">fromSlices(options)</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
295 | <dd><p>Construct a CSG solid from a list of pre-generated slices.
|
296 | See Polygon.prototype.solidFromSlices() for details.</p>
|
297 | </dd>
|
298 | <dt><a href="#fromObject">fromObject(obj)</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
299 | <dd><p>Reconstruct a CSG solid from an object with identical property names.</p>
|
300 | </dd>
|
301 | <dt><a href="#fromCompactBinary">fromCompactBinary(bin)</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
302 | <dd><p>Reconstruct a CSG from the output of toCompactBinary().</p>
|
303 | </dd>
|
304 | <dt><a href="#Line2D">Line2D(normal)</a> ⇒ <code><a href="#Line2D">Line2D</a></code></dt>
|
305 | <dd><p>class Line2D
|
306 | Represents a directional line in 2D space
|
307 | A line is parametrized by its normal vector (perpendicular to the line, rotated 90 degrees counter clockwise)
|
308 | and w. The line passes through the point <normal>.times(w).
|
309 | Equation: p is on line if normal.dot(p)==w</p>
|
310 | </dd>
|
311 | <dt><a href="#OrthoNormalBasis">OrthoNormalBasis(plane, rightvector)</a></dt>
|
312 | <dd><p>class OrthoNormalBasis
|
313 | Reprojects points on a 3D plane onto a 2D plane
|
314 | or from a 2D plane back onto the 3D plane</p>
|
315 | </dd>
|
316 | <dt><a href="#fromPoints">fromPoints(points, [shared], [plane])</a></dt>
|
317 | <dd><p>Create a polygon from the given points.</p>
|
318 | </dd>
|
319 | <dt><a href="#canonicalize">canonicalize()</a> ⇒ <code><a href="#CSG">CSG</a></code> | <code><a href="#CAG">CAG</a></code></dt>
|
320 | <dd><p>Returns a cannoicalized version of the input csg/cag : ie every very close
|
321 | points get deduplicated</p>
|
322 | </dd>
|
323 | <dt><a href="#canonicalizeCSG">canonicalizeCSG()</a> ⇒ <code><a href="#CSG">CSG</a></code></dt>
|
324 | <dd><p>Returns a cannoicalized version of the input csg : ie every very close
|
325 | points get deduplicated</p>
|
326 | </dd>
|
327 | <dt><a href="#bounds">bounds()</a> ⇒ <code><a href="#Vector3D">Array.<Vector3D></a></code></dt>
|
328 | <dd><p>Returns an array of Vector3D, providing minimum coordinates and maximum coordinates
|
329 | of this solid.</p>
|
330 | </dd>
|
331 | </dl>
|
332 |
|
333 | <a name="CAG"></a>
|
334 |
|
335 | ## CAG
|
336 | **Kind**: global class
|
337 |
|
338 | * [CAG](#CAG)
|
339 | * [new CAG()](#new_CAG_new)
|
340 | * [.toPoints()](#CAG+toPoints) ⇒ <code>Array.<points></code>
|
341 | * [.toCompactBinary()](#CAG+toCompactBinary) ⇒ <code>CompactBinary</code>
|
342 |
|
343 | <a name="new_CAG_new"></a>
|
344 |
|
345 | ### new CAG()
|
346 | Class CAG
|
347 | Holds a solid area geometry like CSG but 2D.
|
348 | Each area consists of a number of sides.
|
349 | Each side is a line between 2 points.
|
350 |
|
351 | <a name="CAG+toPoints"></a>
|
352 |
|
353 | ### caG.toPoints() ⇒ <code>Array.<points></code>
|
354 | Convert to a list of points.
|
355 |
|
356 | **Kind**: instance method of [<code>CAG</code>](#CAG)
|
357 | **Returns**: <code>Array.<points></code> - list of points in 2D space
|
358 | <a name="CAG+toCompactBinary"></a>
|
359 |
|
360 | ### caG.toCompactBinary() ⇒ <code>CompactBinary</code>
|
361 | Convert to compact binary form.
|
362 | See fromCompactBinary.
|
363 |
|
364 | **Kind**: instance method of [<code>CAG</code>](#CAG)
|
365 | <a name="CSG"></a>
|
366 |
|
367 | ## CSG
|
368 | **Kind**: global class
|
369 |
|
370 | * [CSG](#CSG)
|
371 | * [new CSG()](#new_CSG_new)
|
372 | * [.union(csg)](#CSG+union) ⇒ [<code>CSG</code>](#CSG)
|
373 | * [.subtract(csg)](#CSG+subtract) ⇒ [<code>CSG</code>](#CSG)
|
374 | * [.intersect(csg)](#CSG+intersect) ⇒ [<code>CSG</code>](#CSG)
|
375 | * [.invert()](#CSG+invert) ⇒ [<code>CSG</code>](#CSG)
|
376 | * [.transform(matrix4x4)](#CSG+transform) ⇒ [<code>CSG</code>](#CSG)
|
377 | * [.mayOverlap(csg)](#CSG+mayOverlap)
|
378 | * [.connectTo(myConnector, otherConnector, mirror, normalrotation)](#CSG+connectTo) ⇒ [<code>CSG</code>](#CSG)
|
379 | * [.setShared(shared)](#CSG+setShared) ⇒ [<code>CSG</code>](#CSG)
|
380 | * [.setColor(args)](#CSG+setColor) ⇒ [<code>CSG</code>](#CSG)
|
381 | * [.getFeatures(features)](#CSG+getFeatures) ⇒ <code>Array.<Float></code>
|
382 | * [.toPolygons()](#CSG+toPolygons) ⇒ [<code>Array.<Polygon></code>](#Polygon)
|
383 | * [.toCompactBinary()](#CSG+toCompactBinary) ⇒ <code>Object</code>
|
384 | * [.toTriangles()](#CSG+toTriangles) ⇒ <code>Polygons</code>
|
385 |
|
386 | <a name="new_CSG_new"></a>
|
387 |
|
388 | ### new CSG()
|
389 | Class CSG
|
390 | Holds a binary space partition tree representing a 3D solid. Two solids can
|
391 | be combined using the `union()`, `subtract()`, and `intersect()` methods.
|
392 |
|
393 | <a name="CSG+union"></a>
|
394 |
|
395 | ### csG.union(csg) ⇒ [<code>CSG</code>](#CSG)
|
396 | Return a new CSG solid representing the space in either this solid or
|
397 | in the given solids. Neither this solid nor the given solids are modified.
|
398 |
|
399 | **Kind**: instance method of [<code>CSG</code>](#CSG)
|
400 | **Returns**: [<code>CSG</code>](#CSG) - new CSG object
|
401 |
|
402 | | Param | Type | Description |
|
403 | | --- | --- | --- |
|
404 | | csg | [<code>Array.<CSG></code>](#CSG) | list of CSG objects |
|
405 |
|
406 | **Example**
|
407 | ```js
|
408 | let C = A.union(B)
|
409 | ```
|
410 | **Example**
|
411 | ```js
|
412 | +-------+ +-------+
|
413 | | | | |
|
414 | | A | | |
|
415 | | +--+----+ = | +----+
|
416 | +----+--+ | +----+ |
|
417 | | B | | |
|
418 | | | | |
|
419 | +-------+ +-------+
|
420 | ```
|
421 | <a name="CSG+subtract"></a>
|
422 |
|
423 | ### csG.subtract(csg) ⇒ [<code>CSG</code>](#CSG)
|
424 | Return a new CSG solid representing space in this solid but
|
425 | not in the given solids. Neither this solid nor the given solids are modified.
|
426 |
|
427 | **Kind**: instance method of [<code>CSG</code>](#CSG)
|
428 | **Returns**: [<code>CSG</code>](#CSG) - new CSG object
|
429 |
|
430 | | Param | Type | Description |
|
431 | | --- | --- | --- |
|
432 | | csg | [<code>Array.<CSG></code>](#CSG) | list of CSG objects |
|
433 |
|
434 | **Example**
|
435 | ```js
|
436 | let C = A.subtract(B)
|
437 | ```
|
438 | **Example**
|
439 | ```js
|
440 | +-------+ +-------+
|
441 | | | | |
|
442 | | A | | |
|
443 | | +--+----+ = | +--+
|
444 | +----+--+ | +----+
|
445 | | B |
|
446 | | |
|
447 | +-------+
|
448 | ```
|
449 | <a name="CSG+intersect"></a>
|
450 |
|
451 | ### csG.intersect(csg) ⇒ [<code>CSG</code>](#CSG)
|
452 | Return a new CSG solid representing space in both this solid and
|
453 | in the given solids. Neither this solid nor the given solids are modified.
|
454 |
|
455 | **Kind**: instance method of [<code>CSG</code>](#CSG)
|
456 | **Returns**: [<code>CSG</code>](#CSG) - new CSG object
|
457 |
|
458 | | Param | Type | Description |
|
459 | | --- | --- | --- |
|
460 | | csg | [<code>Array.<CSG></code>](#CSG) | list of CSG objects |
|
461 |
|
462 | **Example**
|
463 | ```js
|
464 | let C = A.intersect(B)
|
465 | ```
|
466 | **Example**
|
467 | ```js
|
468 | +-------+
|
469 | | |
|
470 | | A |
|
471 | | +--+----+ = +--+
|
472 | +----+--+ | +--+
|
473 | | B |
|
474 | | |
|
475 | +-------+
|
476 | ```
|
477 | <a name="CSG+invert"></a>
|
478 |
|
479 | ### csG.invert() ⇒ [<code>CSG</code>](#CSG)
|
480 | Return a new CSG solid with solid and empty space switched.
|
481 | This solid is not modified.
|
482 |
|
483 | **Kind**: instance method of [<code>CSG</code>](#CSG)
|
484 | **Returns**: [<code>CSG</code>](#CSG) - new CSG object
|
485 | **Example**
|
486 | ```js
|
487 | let B = A.invert()
|
488 | ```
|
489 | <a name="CSG+transform"></a>
|
490 |
|
491 | ### csG.transform(matrix4x4) ⇒ [<code>CSG</code>](#CSG)
|
492 | Return a new CSG solid that is transformed using the given Matrix.
|
493 | Several matrix transformations can be combined before transforming this solid.
|
494 |
|
495 | **Kind**: instance method of [<code>CSG</code>](#CSG)
|
496 | **Returns**: [<code>CSG</code>](#CSG) - new CSG object
|
497 |
|
498 | | Param | Type | Description |
|
499 | | --- | --- | --- |
|
500 | | matrix4x4 | <code>CSG.Matrix4x4</code> | matrix to be applied |
|
501 |
|
502 | **Example**
|
503 | ```js
|
504 | var m = new CSG.Matrix4x4()
|
505 | m = m.multiply(CSG.Matrix4x4.rotationX(40))
|
506 | m = m.multiply(CSG.Matrix4x4.translation([-.5, 0, 0]))
|
507 | let B = A.transform(m)
|
508 | ```
|
509 | <a name="CSG+mayOverlap"></a>
|
510 |
|
511 | ### csG.mayOverlap(csg)
|
512 | returns true if there is a possibility that the two solids overlap
|
513 | returns false if we can be sure that they do not overlap
|
514 | NOTE: this is critical as it is used in UNIONs
|
515 |
|
516 | **Kind**: instance method of [<code>CSG</code>](#CSG)
|
517 |
|
518 | | Param | Type |
|
519 | | --- | --- |
|
520 | | csg | [<code>CSG</code>](#CSG) |
|
521 |
|
522 | <a name="CSG+connectTo"></a>
|
523 |
|
524 | ### csG.connectTo(myConnector, otherConnector, mirror, normalrotation) ⇒ [<code>CSG</code>](#CSG)
|
525 | Connect a solid to another solid, such that two Connectors become connected
|
526 |
|
527 | **Kind**: instance method of [<code>CSG</code>](#CSG)
|
528 | **Returns**: [<code>CSG</code>](#CSG) - this csg, tranformed accordingly
|
529 |
|
530 | | Param | Type | Description |
|
531 | | --- | --- | --- |
|
532 | | myConnector | <code>Connector</code> | a Connector of this solid |
|
533 | | otherConnector | <code>Connector</code> | a Connector to which myConnector should be connected |
|
534 | | mirror | <code>Boolean</code> | false: the 'axis' vectors of the connectors should point in the same direction true: the 'axis' vectors of the connectors should point in opposite direction |
|
535 | | normalrotation | <code>Float</code> | degrees of rotation between the 'normal' vectors of the two connectors |
|
536 |
|
537 | <a name="CSG+setShared"></a>
|
538 |
|
539 | ### csG.setShared(shared) ⇒ [<code>CSG</code>](#CSG)
|
540 | set the .shared property of all polygons
|
541 |
|
542 | **Kind**: instance method of [<code>CSG</code>](#CSG)
|
543 | **Returns**: [<code>CSG</code>](#CSG) - Returns a new CSG solid, the original is unmodified!
|
544 |
|
545 | | Param | Type |
|
546 | | --- | --- |
|
547 | | shared | <code>Object</code> |
|
548 |
|
549 | <a name="CSG+setColor"></a>
|
550 |
|
551 | ### csG.setColor(args) ⇒ [<code>CSG</code>](#CSG)
|
552 | sets the color of this csg: non mutating, returns a new CSG
|
553 |
|
554 | **Kind**: instance method of [<code>CSG</code>](#CSG)
|
555 | **Returns**: [<code>CSG</code>](#CSG) - a copy of this CSG, with the given color
|
556 |
|
557 | | Param | Type |
|
558 | | --- | --- |
|
559 | | args | <code>Object</code> |
|
560 |
|
561 | <a name="CSG+getFeatures"></a>
|
562 |
|
563 | ### csG.getFeatures(features) ⇒ <code>Array.<Float></code>
|
564 | Returns an array of values for the requested features of this solid.
|
565 | Supported Features: 'volume', 'area'
|
566 |
|
567 | **Kind**: instance method of [<code>CSG</code>](#CSG)
|
568 | **Returns**: <code>Array.<Float></code> - values
|
569 |
|
570 | | Param | Type | Description |
|
571 | | --- | --- | --- |
|
572 | | features | <code>Array.<String></code> | list of features to calculate |
|
573 |
|
574 | **Example**
|
575 | ```js
|
576 | let volume = A.getFeatures('volume')
|
577 | let values = A.getFeatures('area','volume')
|
578 | ```
|
579 | <a name="CSG+toPolygons"></a>
|
580 |
|
581 | ### csG.toPolygons() ⇒ [<code>Array.<Polygon></code>](#Polygon)
|
582 | **Kind**: instance method of [<code>CSG</code>](#CSG)
|
583 | **Returns**: [<code>Array.<Polygon></code>](#Polygon) - The list of polygons.
|
584 | <a name="CSG+toCompactBinary"></a>
|
585 |
|
586 | ### csG.toCompactBinary() ⇒ <code>Object</code>
|
587 | returns a compact binary representation of this csg
|
588 | usually used to transfer CSG objects to/from webworkes
|
589 | NOTE: very interesting compact format, with a lot of reusable ideas
|
590 |
|
591 | **Kind**: instance method of [<code>CSG</code>](#CSG)
|
592 | **Returns**: <code>Object</code> - compact binary representation of a CSG
|
593 | <a name="CSG+toTriangles"></a>
|
594 |
|
595 | ### csG.toTriangles() ⇒ <code>Polygons</code>
|
596 | returns the triangles of this csg
|
597 |
|
598 | **Kind**: instance method of [<code>CSG</code>](#CSG)
|
599 | **Returns**: <code>Polygons</code> - triangulated polygons
|
600 | <a name="Path2D"></a>
|
601 |
|
602 | ## Path2D
|
603 | **Kind**: global class
|
604 |
|
605 | * [Path2D](#Path2D)
|
606 | * [new Path2D([points], [closed])](#new_Path2D_new)
|
607 | * _instance_
|
608 | * [.getPoints()](#Path2D+getPoints) ⇒ <code>Array.<Vector2></code>
|
609 | * [.appendPoint(point)](#Path2D+appendPoint) ⇒ [<code>Path2D</code>](#Path2D)
|
610 | * [.appendPoints(points)](#Path2D+appendPoints) ⇒ [<code>Path2D</code>](#Path2D)
|
611 | * [.isClosed()](#Path2D+isClosed) ⇒ <code>Boolean</code>
|
612 | * [.appendBezier(controlpoints, [options])](#Path2D+appendBezier) ⇒ [<code>Path2D</code>](#Path2D)
|
613 | * [.appendArc(endpoint, [options])](#Path2D+appendArc) ⇒ [<code>Path2D</code>](#Path2D)
|
614 | * _static_
|
615 | * [.arc([options])](#Path2D.arc) ⇒ [<code>Path2D</code>](#Path2D)
|
616 |
|
617 | <a name="new_Path2D_new"></a>
|
618 |
|
619 | ### new Path2D([points], [closed])
|
620 | Class Path2D
|
621 | Represents a series of points, connected by infinitely thin lines.
|
622 | A path can be open or closed, i.e. additional line between first and last points.
|
623 | The difference between Path2D and CAG is that a path is a 'thin' line, whereas a CAG is an enclosed area.
|
624 |
|
625 |
|
626 | | Param | Type | Default | Description |
|
627 | | --- | --- | --- | --- |
|
628 | | [points] | [<code>Array.<Vector2D></code>](#Vector2D) | <code>[]</code> | list of points |
|
629 | | [closed] | <code>boolean</code> | <code>false</code> | closer of path |
|
630 |
|
631 | **Example**
|
632 | ```js
|
633 | new CSG.Path2D()
|
634 | new CSG.Path2D([[10,10], [-10,10], [-10,-10], [10,-10]], true) // closed
|
635 | ```
|
636 | <a name="Path2D+getPoints"></a>
|
637 |
|
638 | ### path2D.getPoints() ⇒ <code>Array.<Vector2></code>
|
639 | Get the points that make up the path.
|
640 | note that this is current internal list of points, not an immutable copy.
|
641 |
|
642 | **Kind**: instance method of [<code>Path2D</code>](#Path2D)
|
643 | **Returns**: <code>Array.<Vector2></code> - array of points the make up the path
|
644 | <a name="Path2D+appendPoint"></a>
|
645 |
|
646 | ### path2D.appendPoint(point) ⇒ [<code>Path2D</code>](#Path2D)
|
647 | Append an point to the end of the path.
|
648 |
|
649 | **Kind**: instance method of [<code>Path2D</code>](#Path2D)
|
650 | **Returns**: [<code>Path2D</code>](#Path2D) - new Path2D object (not closed)
|
651 |
|
652 | | Param | Type | Description |
|
653 | | --- | --- | --- |
|
654 | | point | [<code>Vector2D</code>](#Vector2D) | point to append |
|
655 |
|
656 | <a name="Path2D+appendPoints"></a>
|
657 |
|
658 | ### path2D.appendPoints(points) ⇒ [<code>Path2D</code>](#Path2D)
|
659 | Append a list of points to the end of the path.
|
660 |
|
661 | **Kind**: instance method of [<code>Path2D</code>](#Path2D)
|
662 | **Returns**: [<code>Path2D</code>](#Path2D) - new Path2D object (not closed)
|
663 |
|
664 | | Param | Type | Description |
|
665 | | --- | --- | --- |
|
666 | | points | [<code>Array.<Vector2D></code>](#Vector2D) | points to append |
|
667 |
|
668 | <a name="Path2D+isClosed"></a>
|
669 |
|
670 | ### path2D.isClosed() ⇒ <code>Boolean</code>
|
671 | Determine if the path is a closed or not.
|
672 |
|
673 | **Kind**: instance method of [<code>Path2D</code>](#Path2D)
|
674 | **Returns**: <code>Boolean</code> - true when the path is closed, otherwise false
|
675 | <a name="Path2D+appendBezier"></a>
|
676 |
|
677 | ### path2D.appendBezier(controlpoints, [options]) ⇒ [<code>Path2D</code>](#Path2D)
|
678 | Append a Bezier curve to the end of the path, using the control points to transition the curve through start and end points.
|
679 | <br>
|
680 | The Bézier curve starts at the last point in the path,
|
681 | and ends at the last given control point. Other control points are intermediate control points.
|
682 | <br>
|
683 | The first control point may be null to ensure a smooth transition occurs. In this case,
|
684 | the second to last control point of the path is mirrored into the control points of the Bezier curve.
|
685 | In other words, the trailing gradient of the path matches the new gradient of the curve.
|
686 |
|
687 | **Kind**: instance method of [<code>Path2D</code>](#Path2D)
|
688 | **Returns**: [<code>Path2D</code>](#Path2D) - new Path2D object (not closed)
|
689 |
|
690 | | Param | Type | Default | Description |
|
691 | | --- | --- | --- | --- |
|
692 | | controlpoints | [<code>Array.<Vector2D></code>](#Vector2D) | | list of control points |
|
693 | | [options] | <code>Object</code> | | options for construction |
|
694 | | [options.resolution] | <code>Number</code> | <code>defaultResolution2D</code> | number of sides per 360 rotation |
|
695 |
|
696 | **Example**
|
697 | ```js
|
698 | let p5 = new CSG.Path2D([[10,-20]],false);
|
699 | p5 = p5.appendBezier([[10,-10],[25,-10],[25,-20]]);
|
700 | p5 = p5.appendBezier([[25,-30],[40,-30],[40,-20]]);
|
701 | ```
|
702 | <a name="Path2D+appendArc"></a>
|
703 |
|
704 | ### path2D.appendArc(endpoint, [options]) ⇒ [<code>Path2D</code>](#Path2D)
|
705 | Append an arc to the end of the path.
|
706 | This implementation follows the SVG arc specs. For the details see
|
707 | http://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands
|
708 |
|
709 | **Kind**: instance method of [<code>Path2D</code>](#Path2D)
|
710 | **Returns**: [<code>Path2D</code>](#Path2D) - new Path2D object (not closed)
|
711 |
|
712 | | Param | Type | Default | Description |
|
713 | | --- | --- | --- | --- |
|
714 | | endpoint | [<code>Vector2D</code>](#Vector2D) | | end point of arc |
|
715 | | [options] | <code>Object</code> | | options for construction |
|
716 | | [options.radius] | <code>Number</code> | <code>0</code> | radius of arc (X and Y), see also xradius and yradius |
|
717 | | [options.xradius] | <code>Number</code> | <code>0</code> | X radius of arc, see also radius |
|
718 | | [options.yradius] | <code>Number</code> | <code>0</code> | Y radius of arc, see also radius |
|
719 | | [options.xaxisrotation] | <code>Number</code> | <code>0</code> | rotation (in degrees) of the X axis of the arc with respect to the X axis of the coordinate system |
|
720 | | [options.resolution] | <code>Number</code> | <code>defaultResolution2D</code> | number of sides per 360 rotation |
|
721 | | [options.clockwise] | <code>Boolean</code> | <code>false</code> | draw an arc clockwise with respect to the center point |
|
722 | | [options.large] | <code>Boolean</code> | <code>false</code> | draw an arc longer than 180 degrees |
|
723 |
|
724 | **Example**
|
725 | ```js
|
726 | let p1 = new CSG.Path2D([[27.5,-22.96875]],false);
|
727 | p1 = p1.appendPoint([27.5,-3.28125]);
|
728 | p1 = p1.appendArc([12.5,-22.96875],{xradius: 15,yradius: -19.6875,xaxisrotation: 0,clockwise: false,large: false});
|
729 | p1 = p1.close();
|
730 | ```
|
731 | <a name="Path2D.arc"></a>
|
732 |
|
733 | ### Path2D.arc([options]) ⇒ [<code>Path2D</code>](#Path2D)
|
734 | Construct an arc.
|
735 |
|
736 | **Kind**: static method of [<code>Path2D</code>](#Path2D)
|
737 | **Returns**: [<code>Path2D</code>](#Path2D) - new Path2D object (not closed)
|
738 |
|
739 | | Param | Type | Default | Description |
|
740 | | --- | --- | --- | --- |
|
741 | | [options] | <code>Object</code> | | options for construction |
|
742 | | [options.center] | [<code>Vector2D</code>](#Vector2D) | <code>[0,0]</code> | center of circle |
|
743 | | [options.radius] | <code>Number</code> | <code>1</code> | radius of circle |
|
744 | | [options.startangle] | <code>Number</code> | <code>0</code> | starting angle of the arc, in degrees |
|
745 | | [options.endangle] | <code>Number</code> | <code>360</code> | ending angle of the arc, in degrees |
|
746 | | [options.resolution] | <code>Number</code> | <code>defaultResolution2D</code> | number of sides per 360 rotation |
|
747 | | [options.maketangent] | <code>Boolean</code> | <code>false</code> | adds line segments at both ends of the arc to ensure that the gradients at the edges are tangent |
|
748 |
|
749 | **Example**
|
750 | ```js
|
751 | let path = CSG.Path2D.arc({
|
752 | center: [5, 5],
|
753 | radius: 10,
|
754 | startangle: 90,
|
755 | endangle: 180,
|
756 | resolution: 36,
|
757 | maketangent: true
|
758 | });
|
759 | ```
|
760 | <a name="Polygon"></a>
|
761 |
|
762 | ## Polygon
|
763 | **Kind**: global class
|
764 |
|
765 | * [Polygon](#Polygon)
|
766 | * [new Polygon(vertices, [shared], [plane])](#new_Polygon_new)
|
767 | * _instance_
|
768 | * [.checkIfConvex()](#Polygon+checkIfConvex) ⇒ <code>boolean</code>
|
769 | * _static_
|
770 | * [.Shared](#Polygon.Shared)
|
771 | * [new Polygon.Shared(color)](#new_Polygon.Shared_new)
|
772 | * [.fromColor(r, g, b, [a], [color])](#Polygon.Shared.fromColor)
|
773 | * [.createFromPoints(points, [shared], [plane])](#Polygon.createFromPoints)
|
774 |
|
775 | <a name="new_Polygon_new"></a>
|
776 |
|
777 | ### new Polygon(vertices, [shared], [plane])
|
778 | Class Polygon
|
779 | Represents a convex polygon. The vertices used to initialize a polygon must
|
780 | be coplanar and form a convex loop. They do not have to be `Vertex`
|
781 | instances but they must behave similarly (duck typing can be used for
|
782 | customization).
|
783 | <br>
|
784 | Each convex polygon has a `shared` property, which is shared between all
|
785 | polygons that are clones of each other or were split from the same polygon.
|
786 | This can be used to define per-polygon properties (such as surface color).
|
787 | <br>
|
788 | The plane of the polygon is calculated from the vertex coordinates if not provided.
|
789 | The plane can alternatively be passed as the third argument to avoid calculations.
|
790 |
|
791 |
|
792 | | Param | Type | Default | Description |
|
793 | | --- | --- | --- | --- |
|
794 | | vertices | <code>Array.<Vertex></code> | | list of vertices |
|
795 | | [shared] | [<code>Shared</code>](#Polygon.Shared) | <code>defaultShared</code> | shared property to apply |
|
796 | | [plane] | <code>Plane</code> | | plane of the polygon |
|
797 |
|
798 | **Example**
|
799 | ```js
|
800 | const vertices = [
|
801 | new CSG.Vertex(new CSG.Vector3D([0, 0, 0])),
|
802 | new CSG.Vertex(new CSG.Vector3D([0, 10, 0])),
|
803 | new CSG.Vertex(new CSG.Vector3D([0, 10, 10]))
|
804 | ]
|
805 | let observed = new Polygon(vertices)
|
806 | ```
|
807 | <a name="Polygon+checkIfConvex"></a>
|
808 |
|
809 | ### polygon.checkIfConvex() ⇒ <code>boolean</code>
|
810 | Check whether the polygon is convex. (it should be, otherwise we will get unexpected results)
|
811 |
|
812 | **Kind**: instance method of [<code>Polygon</code>](#Polygon)
|
813 | <a name="Polygon.Shared"></a>
|
814 |
|
815 | ### Polygon.Shared
|
816 | **Kind**: static class of [<code>Polygon</code>](#Polygon)
|
817 |
|
818 | * [.Shared](#Polygon.Shared)
|
819 | * [new Polygon.Shared(color)](#new_Polygon.Shared_new)
|
820 | * [.fromColor(r, g, b, [a], [color])](#Polygon.Shared.fromColor)
|
821 |
|
822 | <a name="new_Polygon.Shared_new"></a>
|
823 |
|
824 | #### new Polygon.Shared(color)
|
825 | Class Polygon.Shared
|
826 | Holds the shared properties for each polygon (Currently only color).
|
827 |
|
828 |
|
829 | | Param | Type | Description |
|
830 | | --- | --- | --- |
|
831 | | color | <code>Array.<Array></code> | array containing RGBA values, or null |
|
832 |
|
833 | **Example**
|
834 | ```js
|
835 | let shared = new CSG.Polygon.Shared([0, 0, 0, 1])
|
836 | ```
|
837 | <a name="Polygon.Shared.fromColor"></a>
|
838 |
|
839 | #### Shared.fromColor(r, g, b, [a], [color])
|
840 | Create Polygon.Shared from color values.
|
841 |
|
842 | **Kind**: static method of [<code>Shared</code>](#Polygon.Shared)
|
843 |
|
844 | | Param | Type | Description |
|
845 | | --- | --- | --- |
|
846 | | r | <code>number</code> | value of RED component |
|
847 | | g | <code>number</code> | value of GREEN component |
|
848 | | b | <code>number</code> | value of BLUE component |
|
849 | | [a] | <code>number</code> | value of ALPHA component |
|
850 | | [color] | <code>Array.<Array></code> | OR array containing RGB values (optional Alpha) |
|
851 |
|
852 | **Example**
|
853 | ```js
|
854 | let s1 = Polygon.Shared.fromColor(0,0,0)
|
855 | let s2 = Polygon.Shared.fromColor([0,0,0,1])
|
856 | ```
|
857 | <a name="Polygon.createFromPoints"></a>
|
858 |
|
859 | ### Polygon.createFromPoints(points, [shared], [plane])
|
860 | Create a polygon from the given points.
|
861 |
|
862 | **Kind**: static method of [<code>Polygon</code>](#Polygon)
|
863 |
|
864 | | Param | Type | Default | Description |
|
865 | | --- | --- | --- | --- |
|
866 | | points | <code>Array.<Array></code> | | list of points |
|
867 | | [shared] | [<code>Shared</code>](#Polygon.Shared) | <code>defaultShared</code> | shared property to apply |
|
868 | | [plane] | <code>Plane</code> | | plane of the polygon |
|
869 |
|
870 | **Example**
|
871 | ```js
|
872 | const points = [
|
873 | [0, 0, 0],
|
874 | [0, 10, 0],
|
875 | [0, 10, 10]
|
876 | ]
|
877 | let observed = CSG.Polygon.createFromPoints(points)
|
878 | ```
|
879 | <a name="Vector2D"></a>
|
880 |
|
881 | ## Vector2D
|
882 | **Kind**: global class
|
883 | <a name="new_Vector2D_new"></a>
|
884 |
|
885 | ### new Vector2D()
|
886 | Class Vector2D
|
887 | Represents a 2D vector with X, Y coordinates
|
888 |
|
889 | **Example**
|
890 | ```js
|
891 | new CSG.Vector2D(1, 2);
|
892 | new CSG.Vector2D([1, 2]);
|
893 | new CSG.Vector2D({ x: 1, y: 2});
|
894 | ```
|
895 | <a name="Vector3D"></a>
|
896 |
|
897 | ## Vector3D
|
898 | **Kind**: global class
|
899 | <a name="new_Vector3D_new"></a>
|
900 |
|
901 | ### new Vector3D()
|
902 | Class Vector3D
|
903 | Represents a 3D vector with X, Y, Z coordinates.
|
904 |
|
905 | **Example**
|
906 | ```js
|
907 | new CSG.Vector3D(1, 2, 3);
|
908 | new CSG.Vector3D([1, 2, 3]);
|
909 | new CSG.Vector3D({ x: 1, y: 2, z: 3 });
|
910 | new CSG.Vector3D(1, 2); // assumes z=0
|
911 | new CSG.Vector3D([1, 2]); // assumes z=0
|
912 | ```
|
913 | <a name="defaultResolution2D"></a>
|
914 |
|
915 | ## defaultResolution2D
|
916 | Number of polygons per 360 degree revolution for 2D objects.
|
917 |
|
918 | **Kind**: global constant
|
919 | **Default**: <code>32</code>
|
920 | <a name="defaultResolution3D"></a>
|
921 |
|
922 | ## defaultResolution3D
|
923 | Number of polygons per 360 degree revolution for 3D objects.
|
924 |
|
925 | **Kind**: global constant
|
926 | **Default**: <code>12</code>
|
927 | <a name="EPS"></a>
|
928 |
|
929 | ## EPS
|
930 | Epsilon used during determination of near zero distances.
|
931 |
|
932 | **Kind**: global constant
|
933 | **Default**: <code>0.00001</code>
|
934 | <a name="angleEPS"></a>
|
935 |
|
936 | ## angleEPS
|
937 | Epsilon used during determination of near zero areas.
|
938 |
|
939 | **Kind**: global constant
|
940 | **Default**: <code>0.1</code>
|
941 | <a name="areaEPS"></a>
|
942 |
|
943 | ## areaEPS
|
944 | Epsilon used during determination of near zero areas.
|
945 | This is the minimal area of a minimal polygon.
|
946 |
|
947 | **Kind**: global constant
|
948 | <a name="center"></a>
|
949 |
|
950 | ## center(object(s), options)
|
951 | NOTE: this is not functional YET !!
|
952 | centers the given object(s) on the given axis
|
953 |
|
954 | **Kind**: global function
|
955 |
|
956 | | Param | Type | Description |
|
957 | | --- | --- | --- |
|
958 | | object(s) | <code>Object</code> \| <code>Array</code> | the shapes to center |
|
959 | | options | <code>Object</code> | |
|
960 |
|
961 | <a name="clone"></a>
|
962 |
|
963 | ## clone(obj) ⇒ [<code>CSG</code>](#CSG)
|
964 | clone the given object
|
965 |
|
966 | **Kind**: global function
|
967 | **Returns**: [<code>CSG</code>](#CSG) - new CSG object , a copy of the input
|
968 |
|
969 | | Param | Type | Description |
|
970 | | --- | --- | --- |
|
971 | | obj | <code>Object</code> | the object to clone by |
|
972 |
|
973 | **Example**
|
974 | ```js
|
975 | let copy = clone(sphere())
|
976 | ```
|
977 | <a name="css2rgb"></a>
|
978 |
|
979 | ## css2rgb(String) ⇒
|
980 | Converts an CSS color name to RGB color.
|
981 |
|
982 | **Kind**: global function
|
983 | **Returns**: Array The RGB representation, or [0,0,0] default
|
984 |
|
985 | | Param | Description |
|
986 | | --- | --- |
|
987 | | String | s The CSS color name |
|
988 |
|
989 | <a name="color"></a>
|
990 |
|
991 | ## color(color, objects) ⇒ [<code>CSG</code>](#CSG)
|
992 | apply the given color to the input object(s)
|
993 |
|
994 | **Kind**: global function
|
995 | **Returns**: [<code>CSG</code>](#CSG) - new CSG object , with the given color
|
996 |
|
997 | | Param | Type | Description |
|
998 | | --- | --- | --- |
|
999 | | color | <code>Object</code> | either an array or a hex string of color values |
|
1000 | | objects | <code>Object</code> \| <code>Array</code> | either a single or multiple CSG/CAG objects to color |
|
1001 |
|
1002 | **Example**
|
1003 | ```js
|
1004 | let redSphere = color([1,0,0,1], sphere())
|
1005 | ```
|
1006 | <a name="rgb2hsl"></a>
|
1007 |
|
1008 | ## rgb2hsl(Number, Number, Number) ⇒
|
1009 | Converts an RGB color value to HSL. Conversion formula
|
1010 | adapted from http://en.wikipedia.org/wiki/HSL_color_space.
|
1011 | Assumes r, g, and b are contained in the set [0, 1] and
|
1012 | returns h, s, and l in the set [0, 1].
|
1013 |
|
1014 | **Kind**: global function
|
1015 | **Returns**: Array The HSL representation
|
1016 |
|
1017 | | Param | Description |
|
1018 | | --- | --- |
|
1019 | | Number | r The red color value |
|
1020 | | Number | g The green color value |
|
1021 | | Number | b The blue color value |
|
1022 |
|
1023 | <a name="hsl2rgb"></a>
|
1024 |
|
1025 | ## hsl2rgb(Number, Number, Number) ⇒
|
1026 | Converts an HSL color value to RGB. Conversion formula
|
1027 | adapted from http://en.wikipedia.org/wiki/HSL_color_space.
|
1028 | Assumes h, s, and l are contained in the set [0, 1] and
|
1029 | returns r, g, and b in the set [0, 1].
|
1030 |
|
1031 | **Kind**: global function
|
1032 | **Returns**: Array The RGB representation
|
1033 |
|
1034 | | Param | Description |
|
1035 | | --- | --- |
|
1036 | | Number | h The hue |
|
1037 | | Number | s The saturation |
|
1038 | | Number | l The lightness |
|
1039 |
|
1040 | <a name="rgb2hsv"></a>
|
1041 |
|
1042 | ## rgb2hsv(Number, Number, Number) ⇒
|
1043 | Converts an RGB color value to HSV. Conversion formula
|
1044 | adapted from http://en.wikipedia.org/wiki/HSV_color_space.
|
1045 | Assumes r, g, and b are contained in the set [0, 1] and
|
1046 | returns h, s, and v in the set [0, 1].
|
1047 |
|
1048 | **Kind**: global function
|
1049 | **Returns**: Array The HSV representation
|
1050 |
|
1051 | | Param | Description |
|
1052 | | --- | --- |
|
1053 | | Number | r The red color value |
|
1054 | | Number | g The green color value |
|
1055 | | Number | b The blue color value |
|
1056 |
|
1057 | <a name="hsv2rgb"></a>
|
1058 |
|
1059 | ## hsv2rgb(Number, Number, Number) ⇒
|
1060 | Converts an HSV color value to RGB. Conversion formula
|
1061 | adapted from http://en.wikipedia.org/wiki/HSV_color_space.
|
1062 | Assumes h, s, and v are contained in the set [0, 1] and
|
1063 | returns r, g, and b in the set [0, 1].
|
1064 |
|
1065 | **Kind**: global function
|
1066 | **Returns**: Array The RGB representation
|
1067 |
|
1068 | | Param | Description |
|
1069 | | --- | --- |
|
1070 | | Number | h The hue |
|
1071 | | Number | s The saturation |
|
1072 | | Number | v The value |
|
1073 |
|
1074 | <a name="html2rgb"></a>
|
1075 |
|
1076 | ## html2rgb()
|
1077 | Converts a HTML5 color value (string) to RGB values
|
1078 | See the color input type of HTML5 forms
|
1079 | Conversion formula:
|
1080 | - split the string; "#RRGGBB" into RGB components
|
1081 | - convert the HEX value into RGB values
|
1082 |
|
1083 | **Kind**: global function
|
1084 | <a name="rgb2html"></a>
|
1085 |
|
1086 | ## rgb2html()
|
1087 | Converts RGB color value to HTML5 color value (string)
|
1088 | Conversion forumla:
|
1089 | - convert R, G, B into HEX strings
|
1090 | - return HTML formatted string "#RRGGBB"
|
1091 |
|
1092 | **Kind**: global function
|
1093 | <a name="union"></a>
|
1094 |
|
1095 | ## union(objects) ⇒ [<code>CSG</code>](#CSG)
|
1096 | union/ combine the given shapes
|
1097 |
|
1098 | **Kind**: global function
|
1099 | **Returns**: [<code>CSG</code>](#CSG) - new CSG object, the union of all input shapes
|
1100 |
|
1101 | | Param | Type | Description |
|
1102 | | --- | --- | --- |
|
1103 | | objects | <code>Object(s)</code> \| <code>Array</code> | objects to combine : can be given - one by one: union(a,b,c) or - as an array: union([a,b,c]) |
|
1104 |
|
1105 | **Example**
|
1106 | ```js
|
1107 | let unionOfSpherAndCube = union(sphere(), cube())
|
1108 | ```
|
1109 | <a name="difference"></a>
|
1110 |
|
1111 | ## difference(objects) ⇒ [<code>CSG</code>](#CSG)
|
1112 | difference/ subtraction of the given shapes ie:
|
1113 | cut out C From B From A ie : a - b - c etc
|
1114 |
|
1115 | **Kind**: global function
|
1116 | **Returns**: [<code>CSG</code>](#CSG) - new CSG object, the difference of all input shapes
|
1117 |
|
1118 | | Param | Type | Description |
|
1119 | | --- | --- | --- |
|
1120 | | objects | <code>Object(s)</code> \| <code>Array</code> | objects to subtract can be given - one by one: difference(a,b,c) or - as an array: difference([a,b,c]) |
|
1121 |
|
1122 | **Example**
|
1123 | ```js
|
1124 | let differenceOfSpherAndCube = difference(sphere(), cube())
|
1125 | ```
|
1126 | <a name="intersection"></a>
|
1127 |
|
1128 | ## intersection(objects) ⇒ [<code>CSG</code>](#CSG)
|
1129 | intersection of the given shapes: ie keep only the common parts between the given shapes
|
1130 |
|
1131 | **Kind**: global function
|
1132 | **Returns**: [<code>CSG</code>](#CSG) - new CSG object, the intersection of all input shapes
|
1133 |
|
1134 | | Param | Type | Description |
|
1135 | | --- | --- | --- |
|
1136 | | objects | <code>Object(s)</code> \| <code>Array</code> | objects to intersect can be given - one by one: intersection(a,b,c) or - as an array: intersection([a,b,c]) |
|
1137 |
|
1138 | **Example**
|
1139 | ```js
|
1140 | let intersectionOfSpherAndCube = intersection(sphere(), cube())
|
1141 | ```
|
1142 | <a name="overCutInsideCorners"></a>
|
1143 |
|
1144 | ## overCutInsideCorners(_cag, cutterradius) ⇒ [<code>CAG</code>](#CAG)
|
1145 | cag = cag.overCutInsideCorners(cutterradius);
|
1146 | Using a CNC router it's impossible to cut out a true sharp inside corner. The inside corner
|
1147 | will be rounded due to the radius of the cutter. This function compensates for this by creating
|
1148 | an extra cutout at each inner corner so that the actual cut out shape will be at least as large
|
1149 | as needed.
|
1150 |
|
1151 | **Kind**: global function
|
1152 | **Returns**: [<code>CAG</code>](#CAG) - cag with overcutInsideCorners
|
1153 |
|
1154 | | Param | Type | Description |
|
1155 | | --- | --- | --- |
|
1156 | | _cag | <code>Object</code> | input cag |
|
1157 | | cutterradius | <code>Float</code> | radius to cut inside corners by |
|
1158 |
|
1159 | <a name="sectionCut"></a>
|
1160 |
|
1161 | ## sectionCut(csg, orthobasis)
|
1162 | cuts a csg along a orthobasis
|
1163 |
|
1164 | **Kind**: global function
|
1165 |
|
1166 | | Param | Type | Description |
|
1167 | | --- | --- | --- |
|
1168 | | csg | [<code>CSG</code>](#CSG) | the csg object to cut |
|
1169 | | orthobasis | <code>Orthobasis</code> | the orthobasis to cut along |
|
1170 |
|
1171 | <a name="cutByPlane"></a>
|
1172 |
|
1173 | ## cutByPlane(plane) ⇒ [<code>CSG</code>](#CSG)
|
1174 | Cut the solid by a plane. Returns the solid on the back side of the plane
|
1175 |
|
1176 | **Kind**: global function
|
1177 | **Returns**: [<code>CSG</code>](#CSG) - the solid on the back side of the plane
|
1178 |
|
1179 | | Param | Type |
|
1180 | | --- | --- |
|
1181 | | plane | <code>Plane</code> |
|
1182 |
|
1183 | <a name="expandedShellOfCCSG"></a>
|
1184 |
|
1185 | ## expandedShellOfCCSG(radius, resolution, unionWithThis)
|
1186 | Create the expanded shell of the solid:
|
1187 | All faces are extruded to get a thickness of 2*radius
|
1188 | Cylinders are constructed around every side
|
1189 | Spheres are placed on every vertex
|
1190 | unionWithThis: if true, the resulting solid will be united with 'this' solid;
|
1191 | the result is a true expansion of the solid
|
1192 | If false, returns only the shell
|
1193 |
|
1194 | **Kind**: global function
|
1195 |
|
1196 | | Param | Type |
|
1197 | | --- | --- |
|
1198 | | radius | <code>Float</code> |
|
1199 | | resolution | <code>Integer</code> |
|
1200 | | unionWithThis | <code>Boolean</code> |
|
1201 |
|
1202 | <a name="extrudeInOrthonormalBasis"></a>
|
1203 |
|
1204 | ## extrudeInOrthonormalBasis(cag, orthonormalbasis, depth, [options])
|
1205 | extrude the CAG in a certain plane.
|
1206 | Giving just a plane is not enough, multiple different extrusions in the same plane would be possible
|
1207 | by rotating around the plane's origin. An additional right-hand vector should be specified as well,
|
1208 | and this is exactly a OrthoNormalBasis.
|
1209 |
|
1210 | **Kind**: global function
|
1211 |
|
1212 | | Param | Type | Default | Description |
|
1213 | | --- | --- | --- | --- |
|
1214 | | cag | [<code>CAG</code>](#CAG) | | the cag to extrude |
|
1215 | | orthonormalbasis | <code>Orthonormalbasis</code> | | characterizes the plane in which to extrude |
|
1216 | | depth | <code>Float</code> | | thickness of the extruded shape. Extrusion is done upwards from the plane (unless symmetrical option is set, see below) |
|
1217 | | [options] | <code>Object</code> | | options for construction |
|
1218 | | [options.symmetrical] | <code>Boolean</code> | <code>true</code> | extrude symmetrically in two directions about the plane |
|
1219 |
|
1220 | <a name="extrudeInPlane"></a>
|
1221 |
|
1222 | ## extrudeInPlane(cag, axis1, axis2, depth, [options])
|
1223 | Extrude in a standard cartesian plane, specified by two axis identifiers. Each identifier can be
|
1224 | one of ["X","Y","Z","-X","-Y","-Z"]
|
1225 | The 2d x axis will map to the first given 3D axis, the 2d y axis will map to the second.
|
1226 | See OrthoNormalBasis.GetCartesian for details.
|
1227 |
|
1228 | **Kind**: global function
|
1229 |
|
1230 | | Param | Type | Default | Description |
|
1231 | | --- | --- | --- | --- |
|
1232 | | cag | [<code>CAG</code>](#CAG) | | the cag to extrude |
|
1233 | | axis1 | <code>String</code> | | the first axis |
|
1234 | | axis2 | <code>String</code> | | the second axis |
|
1235 | | depth | <code>Float</code> | | thickness of the extruded shape. Extrusion is done upwards from the plane |
|
1236 | | [options] | <code>Object</code> | | options for construction |
|
1237 | | [options.symmetrical] | <code>Boolean</code> | <code>true</code> | extrude symmetrically in two directions about the plane |
|
1238 |
|
1239 | <a name="extrude"></a>
|
1240 |
|
1241 | ## extrude(cag, [options]) ⇒ [<code>CSG</code>](#CSG)
|
1242 | linear extrusion of 2D shape, with optional twist
|
1243 |
|
1244 | **Kind**: global function
|
1245 | **Returns**: [<code>CSG</code>](#CSG) - the extrude shape, as a CSG object
|
1246 |
|
1247 | | Param | Type | Default | Description |
|
1248 | | --- | --- | --- | --- |
|
1249 | | cag | [<code>CAG</code>](#CAG) | | the cag to extrude |
|
1250 | | [options] | <code>Object</code> | | options for construction |
|
1251 | | [options.offset] | <code>Array</code> | <code>[0,0,1]</code> | The 2d shape is placed in in z=0 plane and extruded into direction <offset> (a 3D vector as a 3 component array) |
|
1252 | | [options.twiststeps] | <code>Boolean</code> | <code>defaultResolution3D</code> | twiststeps determines the resolution of the twist (should be >= 1) |
|
1253 | | [options.twistangle] | <code>Boolean</code> | <code>0</code> | twistangle The final face is rotated <twistangle> degrees. Rotation is done around the origin of the 2d shape (i.e. x=0, y=0) |
|
1254 |
|
1255 | **Example**
|
1256 | ```js
|
1257 | extruded=cag.extrude({offset: [0,0,10], twistangle: 360, twiststeps: 100});
|
1258 | ```
|
1259 | <a name="rotateExtrude"></a>
|
1260 |
|
1261 | ## rotateExtrude(options) ⇒ [<code>CSG</code>](#CSG)
|
1262 | Extrude to into a 3D solid by rotating the origin around the Y axis.
|
1263 | (and turning everything into XY plane)
|
1264 |
|
1265 | **Kind**: global function
|
1266 | **Returns**: [<code>CSG</code>](#CSG) - new 3D solid
|
1267 |
|
1268 | | Param | Type | Default | Description |
|
1269 | | --- | --- | --- | --- |
|
1270 | | options | <code>Object</code> | | options for construction |
|
1271 | | [options.angle] | <code>Number</code> | <code>360</code> | angle of rotation |
|
1272 | | [options.resolution] | <code>Number</code> | <code>defaultResolution3D</code> | number of polygons per 360 degree revolution |
|
1273 |
|
1274 | <a name="linear_extrude"></a>
|
1275 |
|
1276 | ## linear_extrude([options], baseShape) ⇒ [<code>CSG</code>](#CSG)
|
1277 | linear extrusion of the input 2d shape
|
1278 |
|
1279 | **Kind**: global function
|
1280 | **Returns**: [<code>CSG</code>](#CSG) - new extruded shape
|
1281 |
|
1282 | | Param | Type | Default | Description |
|
1283 | | --- | --- | --- | --- |
|
1284 | | [options] | <code>Object</code> | | options for construction |
|
1285 | | [options.height] | <code>Float</code> | <code>1</code> | height of the extruded shape |
|
1286 | | [options.slices] | <code>Integer</code> | <code>10</code> | number of intermediary steps/slices |
|
1287 | | [options.twist] | <code>Integer</code> | <code>0</code> | angle (in degrees to twist the extusion by) |
|
1288 | | [options.center] | <code>Boolean</code> | <code>false</code> | whether to center extrusion or not |
|
1289 | | baseShape | [<code>CAG</code>](#CAG) | | input 2d shape |
|
1290 |
|
1291 | **Example**
|
1292 | ```js
|
1293 | let revolved = linear_extrude({height: 10}, square())
|
1294 | ```
|
1295 | <a name="rotate_extrude"></a>
|
1296 |
|
1297 | ## rotate_extrude([options], baseShape) ⇒ [<code>CSG</code>](#CSG)
|
1298 | rotate extrusion / revolve of the given 2d shape
|
1299 |
|
1300 | **Kind**: global function
|
1301 | **Returns**: [<code>CSG</code>](#CSG) - new extruded shape
|
1302 |
|
1303 | | Param | Type | Default | Description |
|
1304 | | --- | --- | --- | --- |
|
1305 | | [options] | <code>Object</code> | | options for construction |
|
1306 | | [options.fn] | <code>Integer</code> | <code>1</code> | resolution/number of segments of the extrusion |
|
1307 | | [options.startAngle] | <code>Float</code> | <code>1</code> | start angle of the extrusion, in degrees |
|
1308 | | [options.angle] | <code>Float</code> | <code>1</code> | angle of the extrusion, in degrees |
|
1309 | | [options.overflow] | <code>Float</code> | <code>'cap'</code> | what to do with points outside of bounds (+ / - x) : defaults to capping those points to 0 (only supported behaviour for now) |
|
1310 | | baseShape | [<code>CAG</code>](#CAG) | | input 2d shape |
|
1311 |
|
1312 | **Example**
|
1313 | ```js
|
1314 | let revolved = rotate_extrude({fn: 10}, square())
|
1315 | ```
|
1316 | <a name="rectangular_extrude"></a>
|
1317 |
|
1318 | ## rectangular_extrude(basePoints, [options]) ⇒ [<code>CSG</code>](#CSG)
|
1319 | rectangular extrusion of the given array of points
|
1320 |
|
1321 | **Kind**: global function
|
1322 | **Returns**: [<code>CSG</code>](#CSG) - new extruded shape
|
1323 |
|
1324 | | Param | Type | Default | Description |
|
1325 | | --- | --- | --- | --- |
|
1326 | | basePoints | <code>Array</code> | | array of points (nested) to extrude from layed out like [ [0,0], [10,0], [5,10], [0,10] ] |
|
1327 | | [options] | <code>Object</code> | | options for construction |
|
1328 | | [options.h] | <code>Float</code> | <code>1</code> | height of the extruded shape |
|
1329 | | [options.w] | <code>Float</code> | <code>10</code> | width of the extruded shape |
|
1330 | | [options.fn] | <code>Integer</code> | <code>1</code> | resolution/number of segments of the extrusion |
|
1331 | | [options.closed] | <code>Boolean</code> | <code>false</code> | whether to close the input path for the extrusion or not |
|
1332 | | [options.round] | <code>Boolean</code> | <code>true</code> | whether to round the extrusion or not |
|
1333 |
|
1334 | **Example**
|
1335 | ```js
|
1336 | let revolved = rectangular_extrude({height: 10}, square())
|
1337 | ```
|
1338 | <a name="translate"></a>
|
1339 |
|
1340 | ## translate(vector, ...objects) ⇒ [<code>CSG</code>](#CSG)
|
1341 | translate an object in 2D/3D space
|
1342 |
|
1343 | **Kind**: global function
|
1344 | **Returns**: [<code>CSG</code>](#CSG) - new CSG object , translated by the given amount
|
1345 |
|
1346 | | Param | Type | Description |
|
1347 | | --- | --- | --- |
|
1348 | | vector | <code>Object</code> | 3D vector to translate the given object(s) by |
|
1349 | | ...objects | <code>Object(s)</code> \| <code>Array</code> | either a single or multiple CSG/CAG objects to translate |
|
1350 |
|
1351 | **Example**
|
1352 | ```js
|
1353 | let movedSphere = translate([10,2,0], sphere())
|
1354 | ```
|
1355 | <a name="scale"></a>
|
1356 |
|
1357 | ## scale(scale, ...objects) ⇒ [<code>CSG</code>](#CSG)
|
1358 | scale an object in 2D/3D space
|
1359 |
|
1360 | **Kind**: global function
|
1361 | **Returns**: [<code>CSG</code>](#CSG) - new CSG object , scaled by the given amount
|
1362 |
|
1363 | | Param | Type | Description |
|
1364 | | --- | --- | --- |
|
1365 | | scale | <code>Float</code> \| <code>Array</code> | either an array or simple number to scale object(s) by |
|
1366 | | ...objects | <code>Object(s)</code> \| <code>Array</code> | either a single or multiple CSG/CAG objects to scale |
|
1367 |
|
1368 | **Example**
|
1369 | ```js
|
1370 | let scaledSphere = scale([0.2,15,1], sphere())
|
1371 | ```
|
1372 | <a name="rotate"></a>
|
1373 |
|
1374 | ## rotate(rotation, objects) ⇒ [<code>CSG</code>](#CSG)
|
1375 | rotate an object in 2D/3D space
|
1376 |
|
1377 | **Kind**: global function
|
1378 | **Returns**: [<code>CSG</code>](#CSG) - new CSG object , rotated by the given amount
|
1379 |
|
1380 | | Param | Type | Description |
|
1381 | | --- | --- | --- |
|
1382 | | rotation | <code>Float</code> \| <code>Array</code> | either an array or simple number to rotate object(s) by |
|
1383 | | objects | <code>Object(s)</code> \| <code>Array</code> | either a single or multiple CSG/CAG objects to rotate |
|
1384 |
|
1385 | **Example**
|
1386 | ```js
|
1387 | let rotatedSphere = rotate([0.2,15,1], sphere())
|
1388 | ```
|
1389 | <a name="transform"></a>
|
1390 |
|
1391 | ## transform(matrix, ...objects) ⇒ [<code>CSG</code>](#CSG)
|
1392 | apply the given matrix transform to the given objects
|
1393 |
|
1394 | **Kind**: global function
|
1395 | **Returns**: [<code>CSG</code>](#CSG) - new CSG object , transformed
|
1396 |
|
1397 | | Param | Type | Description |
|
1398 | | --- | --- | --- |
|
1399 | | matrix | <code>Array</code> | the 4x4 matrix to apply, as a simple 1d array of 16 elements |
|
1400 | | ...objects | <code>Object(s)</code> \| <code>Array</code> | either a single or multiple CSG/CAG objects to transform |
|
1401 |
|
1402 | **Example**
|
1403 | ```js
|
1404 | const angle = 45
|
1405 | let transformedShape = transform([
|
1406 | cos(angle), -sin(angle), 0, 10,
|
1407 | sin(angle), cos(angle), 0, 20,
|
1408 | 0 , 0, 1, 30,
|
1409 | 0, 0, 0, 1
|
1410 | ], sphere())
|
1411 | ```
|
1412 | <a name="center"></a>
|
1413 |
|
1414 | ## center(axis, ...objects) ⇒ [<code>CSG</code>](#CSG)
|
1415 | center an object in 2D/3D space
|
1416 |
|
1417 | **Kind**: global function
|
1418 | **Returns**: [<code>CSG</code>](#CSG) - new CSG object , translated by the given amount
|
1419 |
|
1420 | | Param | Type | Description |
|
1421 | | --- | --- | --- |
|
1422 | | axis | <code>Boolean</code> \| <code>Array</code> | either an array or single boolean to indicate which axis you want to center on |
|
1423 | | ...objects | <code>Object(s)</code> \| <code>Array</code> | either a single or multiple CSG/CAG objects to translate |
|
1424 |
|
1425 | **Example**
|
1426 | ```js
|
1427 | let movedSphere = center(false, sphere())
|
1428 | ```
|
1429 | <a name="mirror"></a>
|
1430 |
|
1431 | ## mirror(vector, ...objects) ⇒ [<code>CSG</code>](#CSG)
|
1432 | mirror an object in 2D/3D space
|
1433 |
|
1434 | **Kind**: global function
|
1435 | **Returns**: [<code>CSG</code>](#CSG) - new CSG object , mirrored
|
1436 |
|
1437 | | Param | Type | Description |
|
1438 | | --- | --- | --- |
|
1439 | | vector | <code>Array</code> | the axes to mirror the object(s) by |
|
1440 | | ...objects | <code>Object(s)</code> \| <code>Array</code> | either a single or multiple CSG/CAG objects to mirror |
|
1441 |
|
1442 | **Example**
|
1443 | ```js
|
1444 | let rotatedSphere = mirror([0.2,15,1], sphere())
|
1445 | ```
|
1446 | <a name="expand"></a>
|
1447 |
|
1448 | ## expand(radius, object) ⇒ <code>CSG/CAG</code>
|
1449 | expand an object in 2D/3D space
|
1450 |
|
1451 | **Kind**: global function
|
1452 | **Returns**: <code>CSG/CAG</code> - new CSG/CAG object , expanded
|
1453 |
|
1454 | | Param | Type | Description |
|
1455 | | --- | --- | --- |
|
1456 | | radius | <code>float</code> | the radius to expand by |
|
1457 | | object | <code>Object</code> | a CSG/CAG objects to expand |
|
1458 |
|
1459 | **Example**
|
1460 | ```js
|
1461 | let expanededShape = expand([0.2,15,1], sphere())
|
1462 | ```
|
1463 | <a name="contract"></a>
|
1464 |
|
1465 | ## contract(radius, object) ⇒ <code>CSG/CAG</code>
|
1466 | contract an object(s) in 2D/3D space
|
1467 |
|
1468 | **Kind**: global function
|
1469 | **Returns**: <code>CSG/CAG</code> - new CSG/CAG object , contracted
|
1470 |
|
1471 | | Param | Type | Description |
|
1472 | | --- | --- | --- |
|
1473 | | radius | <code>float</code> | the radius to contract by |
|
1474 | | object | <code>Object</code> | a CSG/CAG objects to contract |
|
1475 |
|
1476 | **Example**
|
1477 | ```js
|
1478 | let contractedShape = contract([0.2,15,1], sphere())
|
1479 | ```
|
1480 | <a name="minkowski"></a>
|
1481 |
|
1482 | ## minkowski(objects) ⇒ [<code>CSG</code>](#CSG)
|
1483 | create a minkowski sum of the given shapes
|
1484 |
|
1485 | **Kind**: global function
|
1486 | **Returns**: [<code>CSG</code>](#CSG) - new CSG object , mirrored
|
1487 |
|
1488 | | Param | Type | Description |
|
1489 | | --- | --- | --- |
|
1490 | | objects | <code>Object(s)</code> \| <code>Array</code> | either a single or multiple CSG/CAG objects to create a hull around |
|
1491 |
|
1492 | **Example**
|
1493 | ```js
|
1494 | let hulled = hull(rect(), circle())
|
1495 | ```
|
1496 | <a name="hull"></a>
|
1497 |
|
1498 | ## hull(objects) ⇒ [<code>CSG</code>](#CSG)
|
1499 | create a convex hull of the given shapes
|
1500 |
|
1501 | **Kind**: global function
|
1502 | **Returns**: [<code>CSG</code>](#CSG) - new CSG object , a hull around the given shapes
|
1503 |
|
1504 | | Param | Type | Description |
|
1505 | | --- | --- | --- |
|
1506 | | objects | <code>Object(s)</code> \| <code>Array</code> | either a single or multiple CSG/CAG objects to create a hull around |
|
1507 |
|
1508 | **Example**
|
1509 | ```js
|
1510 | let hulled = hull(rect(), circle())
|
1511 | ```
|
1512 | <a name="chain_hull"></a>
|
1513 |
|
1514 | ## chain_hull(objects) ⇒ [<code>CSG</code>](#CSG)
|
1515 | create a chain hull of the given shapes
|
1516 | Originally "Whosa whatsis" suggested "Chain Hull" ,
|
1517 | as described at https://plus.google.com/u/0/105535247347788377245/posts/aZGXKFX1ACN
|
1518 | essentially hull A+B, B+C, C+D and then union those
|
1519 |
|
1520 | **Kind**: global function
|
1521 | **Returns**: [<code>CSG</code>](#CSG) - new CSG object ,which a chain hull of the inputs
|
1522 |
|
1523 | | Param | Type | Description |
|
1524 | | --- | --- | --- |
|
1525 | | objects | <code>Object(s)</code> \| <code>Array</code> | either a single or multiple CSG/CAG objects to create a chain hull around |
|
1526 |
|
1527 | **Example**
|
1528 | ```js
|
1529 | let hulled = chain_hull(rect(), circle())
|
1530 | ```
|
1531 | <a name="square"></a>
|
1532 |
|
1533 | ## square([options]) ⇒ [<code>CAG</code>](#CAG)
|
1534 | Construct a square/rectangle
|
1535 |
|
1536 | **Kind**: global function
|
1537 | **Returns**: [<code>CAG</code>](#CAG) - new square
|
1538 |
|
1539 | | Param | Type | Default | Description |
|
1540 | | --- | --- | --- | --- |
|
1541 | | [options] | <code>Object</code> | | options for construction |
|
1542 | | [options.size] | <code>Float</code> | <code>1</code> | size of the square, either as array or scalar |
|
1543 | | [options.center] | <code>Boolean</code> | <code>true</code> | wether to center the square/rectangle or not |
|
1544 |
|
1545 | **Example**
|
1546 | ```js
|
1547 | let square1 = square({
|
1548 | size: 10
|
1549 | })
|
1550 | ```
|
1551 | <a name="circle"></a>
|
1552 |
|
1553 | ## circle([options]) ⇒ [<code>CAG</code>](#CAG)
|
1554 | Construct a circle
|
1555 |
|
1556 | **Kind**: global function
|
1557 | **Returns**: [<code>CAG</code>](#CAG) - new circle
|
1558 |
|
1559 | | Param | Type | Default | Description |
|
1560 | | --- | --- | --- | --- |
|
1561 | | [options] | <code>Object</code> | | options for construction |
|
1562 | | [options.r] | <code>Float</code> | <code>1</code> | radius of the circle |
|
1563 | | [options.fn] | <code>Integer</code> | <code>32</code> | segments of circle (ie quality/ resolution) |
|
1564 | | [options.center] | <code>Boolean</code> | <code>true</code> | wether to center the circle or not |
|
1565 |
|
1566 | **Example**
|
1567 | ```js
|
1568 | let circle1 = circle({
|
1569 | r: 10
|
1570 | })
|
1571 | ```
|
1572 | <a name="polygon"></a>
|
1573 |
|
1574 | ## polygon([options]) ⇒ [<code>CAG</code>](#CAG)
|
1575 | Construct a polygon either from arrays of paths and points, or just arrays of points
|
1576 | nested paths (multiple paths) and flat paths are supported
|
1577 |
|
1578 | **Kind**: global function
|
1579 | **Returns**: [<code>CAG</code>](#CAG) - new polygon
|
1580 |
|
1581 | | Param | Type | Description |
|
1582 | | --- | --- | --- |
|
1583 | | [options] | <code>Object</code> | options for construction |
|
1584 | | [options.paths] | <code>Array</code> | paths of the polygon : either flat or nested array |
|
1585 | | [options.points] | <code>Array</code> | points of the polygon : either flat or nested array |
|
1586 |
|
1587 | **Example**
|
1588 | ```js
|
1589 | let poly = polygon([0,1,2,3,4])
|
1590 | or
|
1591 | let poly = polygon({path: [0,1,2,3,4]})
|
1592 | or
|
1593 | let poly = polygon({path: [0,1,2,3,4], points: [2,1,3]})
|
1594 | ```
|
1595 | <a name="triangle"></a>
|
1596 |
|
1597 | ## triangle() ⇒ [<code>CAG</code>](#CAG)
|
1598 | Construct a triangle
|
1599 |
|
1600 | **Kind**: global function
|
1601 | **Returns**: [<code>CAG</code>](#CAG) - new triangle
|
1602 | **Example**
|
1603 | ```js
|
1604 | let triangle = trangle({
|
1605 | length: 10
|
1606 | })
|
1607 | ```
|
1608 | <a name="circle"></a>
|
1609 |
|
1610 | ## circle([options]) ⇒ [<code>CAG</code>](#CAG)
|
1611 | Construct a circle.
|
1612 |
|
1613 | **Kind**: global function
|
1614 | **Returns**: [<code>CAG</code>](#CAG) - new CAG object
|
1615 |
|
1616 | | Param | Type | Default | Description |
|
1617 | | --- | --- | --- | --- |
|
1618 | | [options] | <code>Object</code> | | options for construction |
|
1619 | | [options.center] | [<code>Vector2D</code>](#Vector2D) | <code>[0,0]</code> | center of circle |
|
1620 | | [options.radius] | <code>Number</code> | <code>1</code> | radius of circle |
|
1621 | | [options.resolution] | <code>Number</code> | <code>defaultResolution2D</code> | number of sides per 360 rotation |
|
1622 |
|
1623 | <a name="ellipse"></a>
|
1624 |
|
1625 | ## ellipse([options]) ⇒ [<code>CAG</code>](#CAG)
|
1626 | Construct an ellispe.
|
1627 |
|
1628 | **Kind**: global function
|
1629 | **Returns**: [<code>CAG</code>](#CAG) - new CAG object
|
1630 |
|
1631 | | Param | Type | Default | Description |
|
1632 | | --- | --- | --- | --- |
|
1633 | | [options] | <code>Object</code> | | options for construction |
|
1634 | | [options.center] | [<code>Vector2D</code>](#Vector2D) | <code>[0,0]</code> | center of ellipse |
|
1635 | | [options.radius] | [<code>Vector2D</code>](#Vector2D) | <code>[1,1]</code> | radius of ellipse, width and height |
|
1636 | | [options.resolution] | <code>Number</code> | <code>defaultResolution2D</code> | number of sides per 360 rotation |
|
1637 |
|
1638 | <a name="rectangle"></a>
|
1639 |
|
1640 | ## rectangle([options]) ⇒ [<code>CAG</code>](#CAG)
|
1641 | Construct a rectangle.
|
1642 |
|
1643 | **Kind**: global function
|
1644 | **Returns**: [<code>CAG</code>](#CAG) - new CAG object
|
1645 |
|
1646 | | Param | Type | Default | Description |
|
1647 | | --- | --- | --- | --- |
|
1648 | | [options] | <code>Object</code> | | options for construction |
|
1649 | | [options.center] | [<code>Vector2D</code>](#Vector2D) | <code>[0,0]</code> | center of rectangle |
|
1650 | | [options.radius] | [<code>Vector2D</code>](#Vector2D) | <code>[1,1]</code> | radius of rectangle, width and height |
|
1651 | | [options.corner1] | [<code>Vector2D</code>](#Vector2D) | <code>[0,0]</code> | bottom left corner of rectangle (alternate) |
|
1652 | | [options.corner2] | [<code>Vector2D</code>](#Vector2D) | <code>[0,0]</code> | upper right corner of rectangle (alternate) |
|
1653 |
|
1654 | <a name="roundedRectangle"></a>
|
1655 |
|
1656 | ## roundedRectangle([options]) ⇒ [<code>CAG</code>](#CAG)
|
1657 | Construct a rounded rectangle.
|
1658 |
|
1659 | **Kind**: global function
|
1660 | **Returns**: [<code>CAG</code>](#CAG) - new CAG object
|
1661 |
|
1662 | | Param | Type | Default | Description |
|
1663 | | --- | --- | --- | --- |
|
1664 | | [options] | <code>Object</code> | | options for construction |
|
1665 | | [options.center] | [<code>Vector2D</code>](#Vector2D) | <code>[0,0]</code> | center of rounded rectangle |
|
1666 | | [options.radius] | [<code>Vector2D</code>](#Vector2D) | <code>[1,1]</code> | radius of rounded rectangle, width and height |
|
1667 | | [options.corner1] | [<code>Vector2D</code>](#Vector2D) | <code>[0,0]</code> | bottom left corner of rounded rectangle (alternate) |
|
1668 | | [options.corner2] | [<code>Vector2D</code>](#Vector2D) | <code>[0,0]</code> | upper right corner of rounded rectangle (alternate) |
|
1669 | | [options.roundradius] | <code>Number</code> | <code>0.2</code> | round radius of corners |
|
1670 | | [options.resolution] | <code>Number</code> | <code>defaultResolution2D</code> | number of sides per 360 rotation |
|
1671 |
|
1672 | **Example**
|
1673 | ```js
|
1674 | let r = roundedRectangle({
|
1675 | center: [0, 0],
|
1676 | radius: [5, 10],
|
1677 | roundradius: 2,
|
1678 | resolution: 36,
|
1679 | });
|
1680 | ```
|
1681 | <a name="cube"></a>
|
1682 |
|
1683 | ## cube([options]) ⇒ [<code>CSG</code>](#CSG)
|
1684 | Construct a cuboid
|
1685 |
|
1686 | **Kind**: global function
|
1687 | **Returns**: [<code>CSG</code>](#CSG) - new sphere
|
1688 |
|
1689 | | Param | Type | Default | Description |
|
1690 | | --- | --- | --- | --- |
|
1691 | | [options] | <code>Object</code> | | options for construction |
|
1692 | | [options.size] | <code>Float</code> | <code>1</code> | size of the side of the cuboid : can be either: - a scalar : ie a single float, in which case all dimensions will be the same - or an array: to specify different dimensions along x/y/z |
|
1693 | | [options.fn] | <code>Integer</code> | <code>32</code> | segments of the sphere (ie quality/resolution) |
|
1694 | | [options.fno] | <code>Integer</code> | <code>32</code> | segments of extrusion (ie quality) |
|
1695 | | [options.type] | <code>String</code> | <code>'normal'</code> | type of sphere : either 'normal' or 'geodesic' |
|
1696 |
|
1697 | **Example**
|
1698 | ```js
|
1699 | let cube1 = cube({
|
1700 | r: 10,
|
1701 | fn: 20
|
1702 | })
|
1703 | ```
|
1704 | <a name="sphere"></a>
|
1705 |
|
1706 | ## sphere([options]) ⇒ [<code>CSG</code>](#CSG)
|
1707 | Construct a sphere
|
1708 |
|
1709 | **Kind**: global function
|
1710 | **Returns**: [<code>CSG</code>](#CSG) - new sphere
|
1711 |
|
1712 | | Param | Type | Default | Description |
|
1713 | | --- | --- | --- | --- |
|
1714 | | [options] | <code>Object</code> | | options for construction |
|
1715 | | [options.r] | <code>Float</code> | <code>1</code> | radius of the sphere |
|
1716 | | [options.fn] | <code>Integer</code> | <code>32</code> | segments of the sphere (ie quality/resolution) |
|
1717 | | [options.fno] | <code>Integer</code> | <code>32</code> | segments of extrusion (ie quality) |
|
1718 | | [options.type] | <code>String</code> | <code>'normal'</code> | type of sphere : either 'normal' or 'geodesic' |
|
1719 |
|
1720 | **Example**
|
1721 | ```js
|
1722 | let sphere1 = sphere({
|
1723 | r: 10,
|
1724 | fn: 20
|
1725 | })
|
1726 | ```
|
1727 | <a name="cylinder"></a>
|
1728 |
|
1729 | ## cylinder([options]) ⇒ [<code>CSG</code>](#CSG)
|
1730 | Construct a cylinder
|
1731 |
|
1732 | **Kind**: global function
|
1733 | **Returns**: [<code>CSG</code>](#CSG) - new cylinder
|
1734 |
|
1735 | | Param | Type | Default | Description |
|
1736 | | --- | --- | --- | --- |
|
1737 | | [options] | <code>Object</code> | | options for construction |
|
1738 | | [options.r] | <code>Float</code> | <code>1</code> | radius of the cylinder |
|
1739 | | [options.r1] | <code>Float</code> | <code>1</code> | radius of the top of the cylinder |
|
1740 | | [options.r2] | <code>Float</code> | <code>1</code> | radius of the bottom of the cylinder |
|
1741 | | [options.d] | <code>Float</code> | <code>1</code> | diameter of the cylinder |
|
1742 | | [options.d1] | <code>Float</code> | <code>1</code> | diameter of the top of the cylinder |
|
1743 | | [options.d2] | <code>Float</code> | <code>1</code> | diameter of the bottom of the cylinder |
|
1744 | | [options.fn] | <code>Integer</code> | <code>32</code> | number of sides of the cylinder (ie quality/resolution) |
|
1745 |
|
1746 | **Example**
|
1747 | ```js
|
1748 | let cylinder = cylinder({
|
1749 | d: 10,
|
1750 | fn: 20
|
1751 | })
|
1752 | ```
|
1753 | <a name="torus"></a>
|
1754 |
|
1755 | ## torus([options]) ⇒ [<code>CSG</code>](#CSG)
|
1756 | Construct a torus
|
1757 |
|
1758 | **Kind**: global function
|
1759 | **Returns**: [<code>CSG</code>](#CSG) - new torus
|
1760 |
|
1761 | | Param | Type | Default | Description |
|
1762 | | --- | --- | --- | --- |
|
1763 | | [options] | <code>Object</code> | | options for construction |
|
1764 | | [options.ri] | <code>Float</code> | <code>1</code> | radius of base circle |
|
1765 | | [options.ro] | <code>Float</code> | <code>4</code> | radius offset |
|
1766 | | [options.fni] | <code>Integer</code> | <code>16</code> | segments of base circle (ie quality) |
|
1767 | | [options.fno] | <code>Integer</code> | <code>32</code> | segments of extrusion (ie quality) |
|
1768 | | [options.roti] | <code>Integer</code> | <code>0</code> | rotation angle of base circle |
|
1769 |
|
1770 | **Example**
|
1771 | ```js
|
1772 | let torus1 = torus({
|
1773 | ri: 10
|
1774 | })
|
1775 | ```
|
1776 | <a name="polyhedron"></a>
|
1777 |
|
1778 | ## polyhedron([options]) ⇒ [<code>CSG</code>](#CSG)
|
1779 | Construct a polyhedron from the given triangles/ polygons/points
|
1780 |
|
1781 | **Kind**: global function
|
1782 | **Returns**: [<code>CSG</code>](#CSG) - new polyhedron
|
1783 |
|
1784 | | Param | Type | Description |
|
1785 | | --- | --- | --- |
|
1786 | | [options] | <code>Object</code> | options for construction |
|
1787 | | [options.triangles] | <code>Array</code> | triangles to build the polyhedron from |
|
1788 | | [options.polygons] | <code>Array</code> | polygons to build the polyhedron from |
|
1789 | | [options.points] | <code>Array</code> | points to build the polyhedron from |
|
1790 | | [options.colors] | <code>Array</code> | colors to apply to the polyhedron |
|
1791 |
|
1792 | **Example**
|
1793 | ```js
|
1794 | let torus1 = polyhedron({
|
1795 | points: [...]
|
1796 | })
|
1797 | ```
|
1798 | <a name="cube"></a>
|
1799 |
|
1800 | ## cube([options]) ⇒ [<code>CSG</code>](#CSG)
|
1801 | Construct an axis-aligned solid cuboid.
|
1802 |
|
1803 | **Kind**: global function
|
1804 | **Returns**: [<code>CSG</code>](#CSG) - new 3D solid
|
1805 |
|
1806 | | Param | Type | Default | Description |
|
1807 | | --- | --- | --- | --- |
|
1808 | | [options] | <code>Object</code> | | options for construction |
|
1809 | | [options.center] | <code>Vector3</code> | <code>[0,0,0]</code> | center of cube |
|
1810 | | [options.radius] | <code>Vector3</code> | <code>[1,1,1]</code> | radius of cube, single scalar also possible |
|
1811 |
|
1812 | **Example**
|
1813 | ```js
|
1814 | let cube = CSG.cube({
|
1815 | center: [5, 5, 5],
|
1816 | radius: 5, // scalar radius
|
1817 | });
|
1818 | ```
|
1819 | <a name="sphere"></a>
|
1820 |
|
1821 | ## sphere([options]) ⇒ [<code>CSG</code>](#CSG)
|
1822 | Construct a solid sphere
|
1823 |
|
1824 | **Kind**: global function
|
1825 | **Returns**: [<code>CSG</code>](#CSG) - new 3D solid
|
1826 |
|
1827 | | Param | Type | Default | Description |
|
1828 | | --- | --- | --- | --- |
|
1829 | | [options] | <code>Object</code> | | options for construction |
|
1830 | | [options.center] | <code>Vector3</code> | <code>[0,0,0]</code> | center of sphere |
|
1831 | | [options.radius] | <code>Number</code> | <code>1</code> | radius of sphere |
|
1832 | | [options.resolution] | <code>Number</code> | <code>defaultResolution3D</code> | number of polygons per 360 degree revolution |
|
1833 | | [options.axes] | <code>Array</code> | | an array with 3 vectors for the x, y and z base vectors |
|
1834 |
|
1835 | **Example**
|
1836 | ```js
|
1837 | let sphere = CSG.sphere({
|
1838 | center: [0, 0, 0],
|
1839 | radius: 2,
|
1840 | resolution: 32,
|
1841 | });
|
1842 | ```
|
1843 | <a name="cylinder"></a>
|
1844 |
|
1845 | ## cylinder([options]) ⇒ [<code>CSG</code>](#CSG)
|
1846 | Construct a solid cylinder.
|
1847 |
|
1848 | **Kind**: global function
|
1849 | **Returns**: [<code>CSG</code>](#CSG) - new 3D solid
|
1850 |
|
1851 | | Param | Type | Default | Description |
|
1852 | | --- | --- | --- | --- |
|
1853 | | [options] | <code>Object</code> | | options for construction |
|
1854 | | [options.start] | <code>Vector</code> | <code>[0,-1,0]</code> | start point of cylinder |
|
1855 | | [options.end] | <code>Vector</code> | <code>[0,1,0]</code> | end point of cylinder |
|
1856 | | [options.radius] | <code>Number</code> | <code>1</code> | radius of cylinder, must be scalar |
|
1857 | | [options.resolution] | <code>Number</code> | <code>defaultResolution3D</code> | number of polygons per 360 degree revolution |
|
1858 |
|
1859 | **Example**
|
1860 | ```js
|
1861 | let cylinder = CSG.cylinder({
|
1862 | start: [0, -10, 0],
|
1863 | end: [0, 10, 0],
|
1864 | radius: 10,
|
1865 | resolution: 16
|
1866 | });
|
1867 | ```
|
1868 | <a name="roundedCylinder"></a>
|
1869 |
|
1870 | ## roundedCylinder([options]) ⇒ [<code>CSG</code>](#CSG)
|
1871 | Construct a cylinder with rounded ends.
|
1872 |
|
1873 | **Kind**: global function
|
1874 | **Returns**: [<code>CSG</code>](#CSG) - new 3D solid
|
1875 |
|
1876 | | Param | Type | Default | Description |
|
1877 | | --- | --- | --- | --- |
|
1878 | | [options] | <code>Object</code> | | options for construction |
|
1879 | | [options.start] | <code>Vector3</code> | <code>[0,-1,0]</code> | start point of cylinder |
|
1880 | | [options.end] | <code>Vector3</code> | <code>[0,1,0]</code> | end point of cylinder |
|
1881 | | [options.radius] | <code>Number</code> | <code>1</code> | radius of rounded ends, must be scalar |
|
1882 | | [options.normal] | <code>Vector3</code> | | vector determining the starting angle for tesselation. Should be non-parallel to start.minus(end) |
|
1883 | | [options.resolution] | <code>Number</code> | <code>defaultResolution3D</code> | number of polygons per 360 degree revolution |
|
1884 |
|
1885 | **Example**
|
1886 | ```js
|
1887 | let cylinder = CSG.roundedCylinder({
|
1888 | start: [0, -10, 0],
|
1889 | end: [0, 10, 0],
|
1890 | radius: 2,
|
1891 | resolution: 16
|
1892 | });
|
1893 | ```
|
1894 | <a name="cylinderElliptic"></a>
|
1895 |
|
1896 | ## cylinderElliptic([options]) ⇒ [<code>CSG</code>](#CSG)
|
1897 | Construct an elliptic cylinder.
|
1898 |
|
1899 | **Kind**: global function
|
1900 | **Returns**: [<code>CSG</code>](#CSG) - new 3D solid
|
1901 |
|
1902 | | Param | Type | Default | Description |
|
1903 | | --- | --- | --- | --- |
|
1904 | | [options] | <code>Object</code> | | options for construction |
|
1905 | | [options.start] | <code>Vector3</code> | <code>[0,-1,0]</code> | start point of cylinder |
|
1906 | | [options.end] | <code>Vector3</code> | <code>[0,1,0]</code> | end point of cylinder |
|
1907 | | [options.radius] | [<code>Vector2D</code>](#Vector2D) | <code>[1,1]</code> | radius of rounded ends, must be two dimensional array |
|
1908 | | [options.radiusStart] | [<code>Vector2D</code>](#Vector2D) | <code>[1,1]</code> | OPTIONAL radius of rounded start, must be two dimensional array |
|
1909 | | [options.radiusEnd] | [<code>Vector2D</code>](#Vector2D) | <code>[1,1]</code> | OPTIONAL radius of rounded end, must be two dimensional array |
|
1910 | | [options.resolution] | <code>Number</code> | <code>defaultResolution2D</code> | number of polygons per 360 degree revolution |
|
1911 |
|
1912 | **Example**
|
1913 | ```js
|
1914 | let cylinder = CSG.cylinderElliptic({
|
1915 | start: [0, -10, 0],
|
1916 | end: [0, 10, 0],
|
1917 | radiusStart: [10,5],
|
1918 | radiusEnd: [8,3],
|
1919 | resolution: 16
|
1920 | });
|
1921 | ```
|
1922 | <a name="roundedCube"></a>
|
1923 |
|
1924 | ## roundedCube([options]) ⇒ [<code>CSG</code>](#CSG)
|
1925 | Construct an axis-aligned solid rounded cuboid.
|
1926 |
|
1927 | **Kind**: global function
|
1928 | **Returns**: [<code>CSG</code>](#CSG) - new 3D solid
|
1929 |
|
1930 | | Param | Type | Default | Description |
|
1931 | | --- | --- | --- | --- |
|
1932 | | [options] | <code>Object</code> | | options for construction |
|
1933 | | [options.center] | <code>Vector3</code> | <code>[0,0,0]</code> | center of rounded cube |
|
1934 | | [options.radius] | <code>Vector3</code> | <code>[1,1,1]</code> | radius of rounded cube, single scalar is possible |
|
1935 | | [options.roundradius] | <code>Number</code> | <code>0.2</code> | radius of rounded edges |
|
1936 | | [options.resolution] | <code>Number</code> | <code>defaultResolution3D</code> | number of polygons per 360 degree revolution |
|
1937 |
|
1938 | **Example**
|
1939 | ```js
|
1940 | let cube = CSG.roundedCube({
|
1941 | center: [2, 0, 2],
|
1942 | radius: 15,
|
1943 | roundradius: 2,
|
1944 | resolution: 36,
|
1945 | });
|
1946 | ```
|
1947 | <a name="polyhedron"></a>
|
1948 |
|
1949 | ## polyhedron([options]) ⇒ [<code>CSG</code>](#CSG)
|
1950 | Create a polyhedron using Openscad style arguments.
|
1951 | Define face vertices clockwise looking from outside.
|
1952 |
|
1953 | **Kind**: global function
|
1954 | **Returns**: [<code>CSG</code>](#CSG) - new 3D solid
|
1955 |
|
1956 | | Param | Type | Description |
|
1957 | | --- | --- | --- |
|
1958 | | [options] | <code>Object</code> | options for construction |
|
1959 |
|
1960 | <a name="solidFromSlices"></a>
|
1961 |
|
1962 | ## solidFromSlices(options)
|
1963 | Creates solid from slices (Polygon) by generating walls
|
1964 |
|
1965 | **Kind**: global function
|
1966 |
|
1967 | | Param | Type | Description |
|
1968 | | --- | --- | --- |
|
1969 | | options | <code>Object</code> | Solid generating options - numslices {Number} Number of slices to be generated - callback(t, slice) {Function} Callback function generating slices. arguments: t = [0..1], slice = [0..numslices - 1] return: Polygon or null to skip - loop {Boolean} no flats, only walls, it's used to generate solids like a tor |
|
1970 |
|
1971 | <a name="_addWalls"></a>
|
1972 |
|
1973 | ## _addWalls(walls, bottom, top)
|
1974 | **Kind**: global function
|
1975 |
|
1976 | | Param | Description |
|
1977 | | --- | --- |
|
1978 | | walls | Array of wall polygons |
|
1979 | | bottom | Bottom polygon |
|
1980 | | top | Top polygon |
|
1981 |
|
1982 | <a name="vector_char"></a>
|
1983 |
|
1984 | ## vector_char(x, y, char) ⇒ <code>Object</code>
|
1985 | Construct a with, segments tupple from a character
|
1986 |
|
1987 | **Kind**: global function
|
1988 | **Returns**: <code>Object</code> - { width: X, segments: [...] }
|
1989 |
|
1990 | | Param | Type | Description |
|
1991 | | --- | --- | --- |
|
1992 | | x | <code>Float</code> | x offset |
|
1993 | | y | <code>Float</code> | y offset |
|
1994 | | char | <code>Float</code> | character |
|
1995 |
|
1996 | **Example**
|
1997 | ```js
|
1998 | let charData = vector_char(0, 12.2, 'b')
|
1999 | ```
|
2000 | <a name="vector_text"></a>
|
2001 |
|
2002 | ## vector_text(x, y, string) ⇒ <code>Array</code>
|
2003 | Construct an array of with, segments tupple from a string
|
2004 |
|
2005 | **Kind**: global function
|
2006 | **Returns**: <code>Array</code> - [{ width: X, segments: [...] }]
|
2007 |
|
2008 | | Param | Type | Description |
|
2009 | | --- | --- | --- |
|
2010 | | x | <code>Float</code> | x offset |
|
2011 | | y | <code>Float</code> | y offset |
|
2012 | | string | <code>Float</code> | string |
|
2013 |
|
2014 | **Example**
|
2015 | ```js
|
2016 | let stringData = vector_text(0, 12.2, 'b')
|
2017 | ```
|
2018 | <a name="fromSides"></a>
|
2019 |
|
2020 | ## fromSides(sides) ⇒ [<code>CAG</code>](#CAG)
|
2021 | Construct a CAG from a list of `Side` instances.
|
2022 |
|
2023 | **Kind**: global function
|
2024 | **Returns**: [<code>CAG</code>](#CAG) - new CAG object
|
2025 |
|
2026 | | Param | Type | Description |
|
2027 | | --- | --- | --- |
|
2028 | | sides | <code>Array.<Side></code> | list of sides |
|
2029 |
|
2030 | <a name="fromPoints"></a>
|
2031 |
|
2032 | ## fromPoints(points) ⇒ [<code>CAG</code>](#CAG)
|
2033 | Construct a CAG from a list of points (a polygon).
|
2034 | The rotation direction of the points is not relevant.
|
2035 | The points can define a convex or a concave polygon.
|
2036 | The polygon must not self intersect.
|
2037 |
|
2038 | **Kind**: global function
|
2039 | **Returns**: [<code>CAG</code>](#CAG) - new CAG object
|
2040 |
|
2041 | | Param | Type | Description |
|
2042 | | --- | --- | --- |
|
2043 | | points | <code>Array.<points></code> | list of points in 2D space |
|
2044 |
|
2045 | <a name="fromObject"></a>
|
2046 |
|
2047 | ## fromObject(obj) ⇒ [<code>CAG</code>](#CAG)
|
2048 | Reconstruct a CAG from an object with identical property names.
|
2049 |
|
2050 | **Kind**: global function
|
2051 | **Returns**: [<code>CAG</code>](#CAG) - new CAG object
|
2052 |
|
2053 | | Param | Type | Description |
|
2054 | | --- | --- | --- |
|
2055 | | obj | <code>Object</code> | anonymous object, typically from JSON |
|
2056 |
|
2057 | <a name="fromPointsNoCheck"></a>
|
2058 |
|
2059 | ## fromPointsNoCheck(points) ⇒ [<code>CAG</code>](#CAG)
|
2060 | Construct a CAG from a list of points (a polygon).
|
2061 | Like fromPoints() but does not check if the result is a valid polygon.
|
2062 | The points MUST rotate counter clockwise.
|
2063 | The points can define a convex or a concave polygon.
|
2064 | The polygon must not self intersect.
|
2065 |
|
2066 | **Kind**: global function
|
2067 | **Returns**: [<code>CAG</code>](#CAG) - new CAG object
|
2068 |
|
2069 | | Param | Type | Description |
|
2070 | | --- | --- | --- |
|
2071 | | points | <code>Array.<points></code> | list of points in 2D space |
|
2072 |
|
2073 | <a name="fromPath2"></a>
|
2074 |
|
2075 | ## fromPath2(Path2) ⇒ [<code>CAG</code>](#CAG)
|
2076 | Construct a CAG from a 2d-path (a closed sequence of points).
|
2077 | Like fromPoints() but does not check if the result is a valid polygon.
|
2078 |
|
2079 | **Kind**: global function
|
2080 | **Returns**: [<code>CAG</code>](#CAG) - new CAG object
|
2081 |
|
2082 | | Param | Type | Description |
|
2083 | | --- | --- | --- |
|
2084 | | Path2 | <code>path</code> | a Path2 path |
|
2085 |
|
2086 | <a name="fromCompactBinary"></a>
|
2087 |
|
2088 | ## fromCompactBinary(bin) ⇒ [<code>CAG</code>](#CAG)
|
2089 | Reconstruct a CAG from the output of toCompactBinary().
|
2090 |
|
2091 | **Kind**: global function
|
2092 | **Returns**: [<code>CAG</code>](#CAG) - new CAG object
|
2093 |
|
2094 | | Param | Type | Description |
|
2095 | | --- | --- | --- |
|
2096 | | bin | <code>CompactBinary</code> | see toCompactBinary() |
|
2097 |
|
2098 | <a name="fromPolygons"></a>
|
2099 |
|
2100 | ## fromPolygons(polygons) ⇒ [<code>CSG</code>](#CSG)
|
2101 | Construct a CSG solid from a list of `Polygon` instances.
|
2102 |
|
2103 | **Kind**: global function
|
2104 | **Returns**: [<code>CSG</code>](#CSG) - new CSG object
|
2105 |
|
2106 | | Param | Type | Description |
|
2107 | | --- | --- | --- |
|
2108 | | polygons | [<code>Array.<Polygon></code>](#Polygon) | list of polygons |
|
2109 |
|
2110 | <a name="fromSlices"></a>
|
2111 |
|
2112 | ## fromSlices(options) ⇒ [<code>CSG</code>](#CSG)
|
2113 | Construct a CSG solid from a list of pre-generated slices.
|
2114 | See Polygon.prototype.solidFromSlices() for details.
|
2115 |
|
2116 | **Kind**: global function
|
2117 | **Returns**: [<code>CSG</code>](#CSG) - new CSG object
|
2118 |
|
2119 | | Param | Type | Description |
|
2120 | | --- | --- | --- |
|
2121 | | options | <code>Object</code> | options passed to solidFromSlices() |
|
2122 |
|
2123 | <a name="fromObject"></a>
|
2124 |
|
2125 | ## fromObject(obj) ⇒ [<code>CSG</code>](#CSG)
|
2126 | Reconstruct a CSG solid from an object with identical property names.
|
2127 |
|
2128 | **Kind**: global function
|
2129 | **Returns**: [<code>CSG</code>](#CSG) - new CSG object
|
2130 |
|
2131 | | Param | Type | Description |
|
2132 | | --- | --- | --- |
|
2133 | | obj | <code>Object</code> | anonymous object, typically from JSON |
|
2134 |
|
2135 | <a name="fromCompactBinary"></a>
|
2136 |
|
2137 | ## fromCompactBinary(bin) ⇒ [<code>CSG</code>](#CSG)
|
2138 | Reconstruct a CSG from the output of toCompactBinary().
|
2139 |
|
2140 | **Kind**: global function
|
2141 | **Returns**: [<code>CSG</code>](#CSG) - new CSG object
|
2142 |
|
2143 | | Param | Type | Description |
|
2144 | | --- | --- | --- |
|
2145 | | bin | <code>CompactBinary</code> | see toCompactBinary(). |
|
2146 |
|
2147 | <a name="Line2D"></a>
|
2148 |
|
2149 | ## Line2D(normal) ⇒ [<code>Line2D</code>](#Line2D)
|
2150 | class Line2D
|
2151 | Represents a directional line in 2D space
|
2152 | A line is parametrized by its normal vector (perpendicular to the line, rotated 90 degrees counter clockwise)
|
2153 | and w. The line passes through the point <normal>.times(w).
|
2154 | Equation: p is on line if normal.dot(p)==w
|
2155 |
|
2156 | **Kind**: global function
|
2157 |
|
2158 | | Param | Type | Description |
|
2159 | | --- | --- | --- |
|
2160 | | normal | [<code>Vector2D</code>](#Vector2D) | normal must be a unit vector! |
|
2161 |
|
2162 | <a name="OrthoNormalBasis"></a>
|
2163 |
|
2164 | ## OrthoNormalBasis(plane, rightvector)
|
2165 | class OrthoNormalBasis
|
2166 | Reprojects points on a 3D plane onto a 2D plane
|
2167 | or from a 2D plane back onto the 3D plane
|
2168 |
|
2169 | **Kind**: global function
|
2170 |
|
2171 | | Param | Type |
|
2172 | | --- | --- |
|
2173 | | plane | <code>Plane</code> |
|
2174 | | rightvector | [<code>Vector3D</code>](#Vector3D) \| [<code>Vector2D</code>](#Vector2D) |
|
2175 |
|
2176 | <a name="fromPoints"></a>
|
2177 |
|
2178 | ## fromPoints(points, [shared], [plane])
|
2179 | Create a polygon from the given points.
|
2180 |
|
2181 | **Kind**: global function
|
2182 |
|
2183 | | Param | Type | Default | Description |
|
2184 | | --- | --- | --- | --- |
|
2185 | | points | <code>Array.<Array></code> | | list of points |
|
2186 | | [shared] | [<code>Shared</code>](#Polygon.Shared) | <code>defaultShared</code> | shared property to apply |
|
2187 | | [plane] | <code>Plane</code> | | plane of the polygon |
|
2188 |
|
2189 | **Example**
|
2190 | ```js
|
2191 | const points = [
|
2192 | [0, 0, 0],
|
2193 | [0, 10, 0],
|
2194 | [0, 10, 10]
|
2195 | ]
|
2196 | let polygon = CSG.Polygon.createFromPoints(points)
|
2197 | ```
|
2198 | <a name="canonicalize"></a>
|
2199 |
|
2200 | ## canonicalize() ⇒ [<code>CSG</code>](#CSG) \| [<code>CAG</code>](#CAG)
|
2201 | Returns a cannoicalized version of the input csg/cag : ie every very close
|
2202 | points get deduplicated
|
2203 |
|
2204 | **Kind**: global function
|
2205 | **Example**
|
2206 | ```js
|
2207 | let rawInput = someCSGORCAGMakingFunction()
|
2208 | let canonicalized= canonicalize(rawInput)
|
2209 | ```
|
2210 | <a name="canonicalizeCSG"></a>
|
2211 |
|
2212 | ## canonicalizeCSG() ⇒ [<code>CSG</code>](#CSG)
|
2213 | Returns a cannoicalized version of the input csg : ie every very close
|
2214 | points get deduplicated
|
2215 |
|
2216 | **Kind**: global function
|
2217 | **Example**
|
2218 | ```js
|
2219 | let rawCSG = someCSGMakingFunction()
|
2220 | let canonicalizedCSG = canonicalize(rawCSG)
|
2221 | ```
|
2222 | <a name="bounds"></a>
|
2223 |
|
2224 | ## bounds() ⇒ [<code>Array.<Vector3D></code>](#Vector3D)
|
2225 | Returns an array of Vector3D, providing minimum coordinates and maximum coordinates
|
2226 | of this solid.
|
2227 |
|
2228 | **Kind**: global function
|
2229 | **Example**
|
2230 | ```js
|
2231 | let bounds = A.getBounds()
|
2232 | let minX = bounds[0].x
|
2233 | ```
|