Code Monkey home page Code Monkey logo

mesh-plane-intersection's Introduction

mesh-plane-intersection

A header-only C++ class for intersecting a triangulated mesh with a plane.

It returns the intersecting segments, joined into open and/or closed polylines.

The class is templated to suit your required floating point coordinate type and integer index type. For example here we will use a typedef for easy reference:

#include "MeshPlaneIntersect.hpp"
typedef MeshPlaneIntersect<double, int> Intersector;

We then create a mesh object object for the intersection. The mesh consists of vertices (points) in 3D space and a list of triangles (three point indices) that make up the faces.

// create some example vertices
std::vector<Intersector::Vec3D> vertices{
    {1,0,-1},
    {3,0,1},
    {7,0,-1}
};

// create a face that links the first three vertices
std::vector<Intersector::Face> faces{
    {0,1,2}
};

// create the mesh object referencing the vertices and faces
Intersector::Mesh mesh(vertices, faces);

Finally, we need a plane to intersect with our mesh

// by default the plane has an origin at (0,0,0) and normal (0,0,1)
// these can be modified, but we can also just use the default
Intersector::Plane plane;

To carry out the intersection we simply call:

auto result = mesh.Intersect(plane);
// the result is a vector of Path3D objects, which are planar polylines
// in 3D space. They have an additional attribute 'isClosed' to determine
// if the path forms a closed loop. if false, the path is open
// in this case we expect one, open Path3D with one segment

There is a further method "Clip" which, as well as returning the intersection polygons, also returns the polygons around any free edges on the positive side of the intersection plane.

auto result = mesh.Clip(plane);
// the result type is the same as above, but the polylines
// are not neccessarily planar.
// in this case we expect one, closed Path3D with three segments

There is a test project that verifies the result for a number of cases. If you come across an unexpected result then please let me know.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.