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 } });
      

    measure

    • Measures the volume a closed triangle mesh encloses, with a sign: positive when its triangles face outwards by the right-hand rule, negative when they all face inwards.

      A mesh that is not closed has no inside, and the number it gives means nothing. Example: a unit cube facing outwards -> 1

      Parameters

      Returns number

      The enclosed volume in cubic model units

      const volume = bitbybit.mesh.signedVolume({ mesh: [[[0, 0, 0], [0, 1, 0], [1, 0, 0]], [[0, 0, 0], [1, 0, 0], [0, 0, 1]], [[0, 0, 0], [0, 0, 1], [0, 1, 0]], [[1, 0, 0], [0, 1, 0], [0, 0, 1]]] });
      

    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 Bit.Inputs.Base.Point3[][]

      One point list per intersection curve

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

    polygon

    • Cuts a flat polygon, with any holes through it, into triangles.

      Every corner stays a corner of a triangle, so neighbouring polygons give a mesh closed along the edges they share. The triangles face the way the outline turns, by the right-hand rule; holes may run either way. Example: a 4 by 4 square -> two triangles

      Parameters

      Returns Mesh3

      The triangles, each three points

      const triangles = bitbybit.mesh.triangulatePolygon({ points: [[0, 0, 0], [4, 0, 0], [4, 4, 0], [0, 4, 0]], holes: [[[1, 1, 0], [3, 1, 0], [3, 3, 0], [1, 3, 0]]] });
      

    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,
      });