meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
en:design_guide_polyhedron [2020/11/28 02:18]
JSCAD Editor created
en:design_guide_polyhedron [2022/04/13 06:57] (current)
rozek included "require" statement
Line 7: Line 7:
 //[[http://www.mathsisfun.com/geometry/polyhedron.html|Learn about polyhedrons at MathIsFun.com]]// //[[http://www.mathsisfun.com/geometry/polyhedron.html|Learn about polyhedrons at MathIsFun.com]]//
  
-Create a polyhedron with a list of points and a list of triangles or polygons. The point list is all the vertexes of the shape, the triangle list is how the points relates to the surfaces of the polyhedron+Create a polyhedron from a list of ''points'' and a list of ''faces''. The ''points'' list all the vertexes of the shape, while the ''faces'' define the points used within each face. 
 + 
 +//Note: The order of the points must be consistent, defining 'inward' or 'outward' facing polygons.//
  
 <code javascript> <code javascript>
-polyhedron({      // openscad-like (e.g. pyramid) +const { polyhedron } = require('@jscad/modeling').primitives 
-  points[ [10,10,0],[10,-10,0],[-10,-10,0],[-10,10,0], // the four points at base + 
-            [0,0,10] ],                                  // the apex point  +const points [ [10, 10, 0], [10, -10, 0], [-10, -10, 0], [-10, 10, 0], [0, 0, 10] ] 
-  triangles: [ [0,1,4],[1,2,4],[2,3,4],[3,0,4],          // each triangle side +const faces = [ [0, 1, 4], [1, 2, 4], [2, 3, 4], [3, 0, 4], [1, 0, 3], [2, 1, 3] ] 
-               [1,0,3],[2,1,3] ]                         // two triangles for square base +const myshape = polyhedron({points, faces, orientation: 'inward'})
-});+
 </code> </code>
  
-Additionally you can also define `polygons: [ [0,1,4,5], [..] ]` too, not just `triangles:`. 
- 
-You can also create a polyhedron at a more low-level. 
- 
-<code javascript> 
-var polygons = []; 
-polygons.push(new CSG.Polygon([ 
-      new CSG.Vertex(new CSG.Vector3D(-5,-5,0)), 
-      new CSG.Vertex(new CSG.Vector3D(2,2,5)), 
-      new CSG.Vertex(new CSG.Vector3D(3,3,15)) 
-   ]) 
-); 
-// add more polygons and finally: 
-solid = CSG.fromPolygons(polygons); 
-</code>