Bitbybit Docs
    Preparing search index...

    Class MeshBitByBit

    Geometry on plain triangle meshes: a mesh is a list of triangles, each three points. The methods here work out the plane of a triangle, the distance from a point to a plane, and where two meshes cut through each other, as segments, as polylines or as point lists. They need no CAD kernel, so they run on any triangulated data.

    Index

    Constructors

    base

    • Measures how far a point is from a plane, with a sign: positive on the side the normal points to, negative on the other.

      Example: point [0,5,0] and the XZ plane with normal [0,1,0] -> 5

      Parameters

      Returns number

      The signed distance in model units

      const above = bitbybit.mesh.signedDistanceToPlane({ point: [0, 5, 0], plane: { normal: [0, 1, 0], d: 0 } });
      

    mesh

    • Finds every segment where the surfaces of two meshes cut through each other, testing each triangle of one against each triangle of the other.

      Example: a cube mesh and a sphere mesh -> the segments that together trace their intersection curve

      Parameters

      Returns Segment3[]

      The crossing segments, in no particular order

      const segments = bitbybit.mesh.meshMeshIntersectionSegments({ mesh1: cubeTriangles, mesh2: sphereTriangles, tolerance: 1e-7 });
      
    • Finds where the surfaces of two meshes cut through each other and joins the pieces into polylines, closed where the curve loops.

      Example: a cube mesh and a sphere mesh -> closed polylines where the two surfaces meet

      Parameters

      Returns Polyline3[]

      The intersection curves as polylines

      const curves = bitbybit.mesh.meshMeshIntersectionPolylines({ mesh1: cubeTriangles, mesh2: sphereTriangles, tolerance: 1e-7 });
      
    • Finds where the surfaces of two meshes cut through each other, as one list of points per curve.

      A closed curve repeats its first point at the end so the loop is explicit. Example: a cube mesh and a sphere mesh -> point lists tracing where the two surfaces meet

      Parameters

      Returns Point3[][]

      One point list per intersection curve

      const curves = bitbybit.mesh.meshMeshIntersectionPoints({ mesh1: cubeTriangles, mesh2: sphereTriangles, tolerance: 1e-7 });
      

    traingle

    • Finds the plane a triangle lies in: its unit normal and its distance from the origin along that normal.

      The normal follows the right-hand rule around the triangle's points. A triangle with no area, whose points are on one line, has no plane and gives undefined. Example: [[0,0,0], [1,0,0], [0,1,0]] -> { normal: [0,0,1], d: 0 }

      Parameters

      Returns TrianglePlane3

      The plane, or undefined for a flat triangle

      const plane = bitbybit.mesh.calculateTrianglePlane({ triangle: [[0, 0, 0], [1, 0, 0], [0, 1, 0]], tolerance: 1e-7 });
      
    • Finds the segment where two triangles cut through each other.

      Triangles that do not touch, are parallel, or lie in the same plane give undefined. Example: a triangle in the XY plane and one standing across it -> the segment where they cross

      Parameters

      Returns Segment3

      The crossing segment, or undefined when there is none

      const cut = bitbybit.mesh.triangleTriangleIntersection({
      triangle1: [[0, 0, 0], [2, 0, 0], [1, 2, 0]],
      triangle2: [[1, -1, 1], [1, 1, 1], [1, 1, -1]],
      tolerance: 1e-7,
      });