Polyhedra Viewer

repository·canon·Indexed 43 days ago

https://github.com/tesseralis/polyhedra-viewer

An interactive tool for transforming and viewing convex polyhedra, including Platonic, Archimedean, Prisms, Antiprisms, and Johnson Solids. Version 0.1.0 provides a comprehensive API for defining uniform polyhedra via Classical and Composite classes, managing polyhedral, cyclic, and dihedral symmetry groups, and performing geometric operations like vertex deduplication and orthonormal transforms.

Tokens
6.6K
Snippets
31
Records
36
Agent score
55%

What's inside Polyhedra Viewer

  1. Install and run Polyhedra Viewer locally

    canon

    To set up the Polyhedra Viewer development environment, clone the repository, install dependencies using yarn, and start the local development server.

    1. Clone the repository: git clone https://github.com/tesseralis/polyhedra-viewer
    2. Navigate to the directory: cd polyhedra-viewer
    3. Install dependencies: yarn
    4. Start the development server: yarn start

    The site will be available at http://localhost:3000.

    git clone https://github.com/tesseralis/polyhedra-viewer
    cd polyhedra-viewer
    yarn
    yarn start
  2. Calculate polygon normals with getNormal() and getNormalRay()

    canon

    Use these functions to find the orientation of a polygon based on its ordered vertices:

    • getNormal(vertices): Returns a normalized vector perpendicular to the polygon surface.
    • getNormalRay(vertices): Returns a Ray3D where the origin is the polygon's centroid and the direction is the polygon's normal.
    import { getNormal, getNormalRay, Vec3D } from "src/math/geom"
    
    const vertices: Vec3D[] = [/* ordered vertices of a polygon */]
    const normal = getNormal(vertices)
    const normalRay = getNormalRay(vertices)
  3. Calculate the snub angle of a polyhedron

    canon

    Use calcSnubAngle to determine the specific rotation angle required for snubbing a polyhedron. This calculation is based on the Classical specification and a target Facet (either 'face' or 'vertex'). The function determines the angle by analyzing the relationship between expanded faces and their neighbors in the geometry.

    import { calcSnubAngle } from './math/operations/resizeOps';
    // Assuming specs and facet are provided by the Classical module
    const angle = calcSnubAngle(specs, 'face');
  4. Access polyhedral operations via the `operations` object

    canon

    The operations object provides a centralized registry of all available polyhedral transformation functions. These operations are categorized into different types such as resize operations (dual, expand, snub, etc.), prism operations (elongate, gyroelongate, etc.), and cut-paste operations (augment, diminish, etc.). You can use the keys of this object to identify available operations.

    import { operations } from './math/operations';
    
    // Example: Accessing a specific operation
    const dualOp = operations.dual;
    const expandOp = operations.expand;
    const augmentOp = operations.augment;
  5. Query and manipulate Composite specifications

    canon

    The Composite class provides several methods to inspect the state of a composite polyhedron:

    • withData(data: Partial<CompositeData>): Returns a new Composite instance with merged data.
    • totalCount(): Returns the sum of augmented, diminished, and gyrate counts.
    • isMono(), isBi(), isTri(): Returns true if the total count of modifications is 1, 2, or 3 respectively.
    • isAugmented(), isDiminished(), isGyrate(): Returns true if the respective modification count is greater than 0.
    • isPara(), isMeta(): Returns true if the align property matches 'para' or 'meta' (only applicable if isBi() is true).
    • equals(s2: Specs): Performs a deep equality check between two specifications, ensuring both are Composite and comparing their source and modification data.
  6. Core Polyhedral Types and Classes

    canon

    The polyhedra module provides the fundamental building blocks for representing 3D polyhedral structures. The primary entities are:

    • Polyhedron: The top-level container representing a complete polyhedral solid.
    • Vertex: Represents a point in 3D space.
    • Edge: Represents a line segment connecting two vertices.
    • Face: Represents a planar surface bounded by edges.
    • FaceLike: An interface or type describing objects that behave like faces.
    • Cap: Represents a capping element for polyhedral structures.

    These types are used to construct and manipulate complex geometric solids within the viewer.

    import Polyhedron, { Vertex, Edge, Face } from 'src/math/polyhedra';
    
    // Example conceptual usage:
    // const polyhedron = new Polyhedron(vertices, faces, edges);
    // const vertex = new Vertex(x, y, z);
  7. Calculate the plane from points with getPlane()

    canon

    The getPlane function returns a Plane object containing the plane defined by the first three points in the provided array.

    Note: The input array must contain at least three points, otherwise it throws an error.

    import { getPlane, Vec3D } from "src/math/geom"
    
    const points: Vec3D[] = [/* at least 3 Vec3D instances */]
    const plane = getPlane(points)
  8. Retrieve valid PolyhedronSpecs for a geometry

    canon

    The getValidSpecs(geom) generator function returns all matching PolyhedronSpecs for a given Polyhedron geometry, automatically handling chirality.

    It iterates through all available specs for the polyhedron's name and:

    1. Yields specs that are not chiral.
    2. For classical chiral specs, yields them with the correct twist determined by snubChirality(geom).
    3. For capstone chiral specs, yields them with the correct twist determined by capstoneChirality(geom).
    for (const specs of getValidSpecs(myPolyhedron)) {
      // Use the specs to work with the correct chiral version of the polyhedron
      console.log(specs.canonicalName());
    }
  9. Query classical polyhedra using Classical.query

    canon

    The Classical class provides a static query property, which is an instance of Queries initialized with all possible classical polyhedra. You can use this to search or filter the set of all classical uniform polyhedra.

    import Classical from "src/data/specs/Classical";
    
    // Example: Accessing the query interface
    const results = Classical.query.find(p => p.isSnub());
  10. Use the dual, expand, snub, twist, and contract operations

    canon

    The module exports several Operation instances that can be used to transform polyhedra. These operations are built using a combination of resizing and geometric transformations.

    • dual: Performs a dual transformation.
    • expand: Expands a regular solid into a cantellated or snub solid.
    • snub: Performs a snub operation, often involving a twist.
    • twist: Applies a twist to a cantellated solid to create a snub solid.
    • contract: The inverse of expansion/snubbing, used to push faces back towards the center.
  11. Query all available Composite polyhedra

    canon

    You can access a collection of all pre-defined Composite polyhedra using the static Composite.query property. This allows you to filter and find specific composite solids within the library's dataset.

    // Example of querying the composite collection
    const specificComposites = Composite.query.where(s => s.isAugmented());