NetDEM v1.0
Loading...
Searching...
No Matches
netdem::Triangle Class Reference

A class representing a triangle in 3D space. More...

#include <shape_triangle.hpp>

Inheritance diagram for netdem::Triangle:
netdem::Shape

Public Member Functions

 Triangle ()
 Default constructor.
 
 Triangle (Vec3d const &a, Vec3d const &b, Vec3d const &c)
 Constructor with specified vertices.
 
nlohmann::json PackJson () override
 Pack the Triangle object into a JSON structure.
 
void InitFromJson (nlohmann::json const &js) override
 Initialize the Triangle object from a JSON structure.
 
void SetVertices (Vec3d const &a, Vec3d const &b, Vec3d const &c)
 Set the vertices of the Triangle object.
 
void Init ()
 Initialize the Triangle object.
 
void Translate (Vec3d const &pos) override
 Translate the Triangle object.
 
void UpdateSurfaceNodes () override
 Update the surface nodes of the Triangle object.
 
void UpdateShapeProperties () override
 Update the shape properties of the Triangle object.
 
ShapeClone () const override
 Clone the Triangle object.
 
STLModel GetSTLModel (int num_nodes=200) override
 Generate an STL model for the Triangle object.
 
std::tuple< Vec3d, Vec3dGetBoundAABB () const override
 Compute the axis-aligned bounding box of the Triangle object.
 
std::tuple< Vec3d, Vec3dGetBoundAABB (Vec3d const &pos, Vec4d const &quat) const override
 Compute the axis-aligned bounding box of the Triangle object.
 
Vec3d SupportPoint (Vec3d const &dir) override
 Calculate the support point of the Triangle object in a given direction.
 
VecXT< Vec3dSupportPoints (Vec3d const &dir) override
 Calculate the support points of the Triangle object in a given direction.
 
double SignedDistance (Vec3d const &pos) const override
 Compute the signed distance between a point and the Triangle object.
 
Vec3d SurfacePoint (Vec3d const &pos) override
 Compute the surface point of the Triangle object closest to a given point.
 
bool CheckEnclose (Vec3d const &pos) const override
 Check if a point is enclosed by the Triangle object.
 
- Public Member Functions inherited from netdem::Shape
virtual void InitFromJsonFile (std::string const &js_file)
 Initializes the shape instance from a JSON file.
 
virtual double GetSize () const
 Return shape size, which is defined as the diameter of equal-volume sphere.
 
virtual double GetVolume () const
 Return the volume of the shape.
 
virtual Mat3d const & GetInertia () const
 Return the inertia of the shape.
 
Vec3d GetInertiaPrincipal () const
 Return the principal inertia of the shape.
 
virtual double GetBoundSphereRadius () const
 Return the inertia of the shape.
 
virtual double GetSkin () const
 Return skin size of the shape.
 
virtual double GetSkinFactor () const
 Return skin factor of the shape.
 
virtual double GetSurfaceNodeNum () const
 Return number of surface nodes of the shape.
 
virtual VecXT< Vec3d > const & GetSurfaceNodes () const
 Return surface nodes of the shape.
 
virtual VecXT< double > const & GetSurfaceNodeAreas () const
 Return surface area associated with each surface node.
 
virtual double GetSurfaceNodeSpacing () const
 Return spacing of surface nodes.
 
const STLModelGetRenderMesh () const
 Return the surface mesh for rendering.
 
bool CheckConvexity ()
 Return the convexity of the shape.
 
virtual void UpdateRenderMesh (int num_nodes=200)
 Initializes the surface mesh for rendering.
 
virtual void SetSize (double d)
 Sets the size of the shape instance.
 
virtual void SetSkin (double sk)
 Set skin size of the shape.
 
virtual void SetSkinFactor (double sk_factor)
 Set skin size factor (skin = size by skin size factor) of the shape.
 
virtual void EnableSurfaceNodes ()
 Enable the use of surface nodes.
 
virtual void DisableSurfaceNodes ()
 Disable the use of surface nodes.
 
virtual bool IsSurfaceNodesEnabled ()
 Check if the use of surface nodes is enabled.
 
virtual void SetSurfaceNodeNum (int num)
 Set number of surface nodes of the shape.
 
virtual void SetSurfaceNodes (VecXT< Vec3d > const &nodes)
 Set the surface nodes of the shape.
 
virtual void SetSurfaceNodes (STLModel const &surf_stl)
 Set the surface nodes of the shape.
 
virtual void SaveAsVTK (std::string const &filename)
 Saves the shape instance as a VTK file.
 
virtual void SaveAsSTL (std::string const &filename)
 Saves the shape instance as an STL file.
 
virtual bool CheckPrincipal () const
 Determines whether the shape is in principal configuration.
 
virtual void Print ()
 Prints the properties of the shape instance.
 
virtual ~Shape ()
 Destructor for the Shape class.
 

Public Attributes

Mat3d vertices
 The three vertices that define the triangle.
 
Vec3d dir_n {0, 0, 1}
 The normal direction of the triangle.
 
- Public Attributes inherited from netdem::Shape
int id {0}
 ID of the shape instance.
 
std::string label {"default"}
 Label of the shape instance.
 
Type shape_type {Type::none}
 Type of the shape instance.
 
std::string shape_name {"shape"}
 Name of the shape instance.
 
bool use_customized_solver {false}
 Determines whether to use a customized contact solver or not.
 
STLModel render_mesh
 Surface mesh for rendering.
 

Additional Inherited Members

- Public Types inherited from netdem::Shape
enum  Type {
  none , point_sphere , sphere , spherical_harmonics ,
  trimesh , trimesh_convex , ellipsoid , polybezier ,
  triangle , plane , cylinder , poly_super_ellipsoid ,
  poly_super_quadrics , level_set , netsdf , coded_netsdf ,
  num_shapes
}
 Enumeration for different types of shapes. More...
 
- Static Public Member Functions inherited from netdem::Shape
static MatNd< 8, 3 > VerticesOfAABB (Vec3d const &bmin, Vec3d const &bmax)
 Gets the vertices of the boundary AABB of the shape instance.
 
- Protected Attributes inherited from netdem::Shape
double size {1.0}
 Size and volume of the shape instance.
 
double volume {0.5236}
 Volume of the shape instance.
 
Mat3d inertia {{{0.05236, 0, 0}, {0, 0.05236, 0}, {0, 0, 0.05236}}}
 Inertia tensor of the shape instance.
 
double bound_sphere_radius {0.5}
 Radius of the bounding sphere used for broad-phase contact detection.
 
double skin {0.025}
 Skin thickness used for broad-phase contact detection.
 
double skin_factor {0.05}
 Factor used to adjust the skin thickness.
 
Vec3d bound_aabb_min {-0.5, -0.5, -0.5}
 Minimum bounds of the AABB used for broad-phase contact detection.
 
Vec3d bound_aabb_max {0.5, 0.5, 0.5}
 Maximum bounds of the AABB used for broad-phase contact detection.
 
bool is_convex {true}
 Determines whether the shape instance is convex or not.
 
bool use_surface_nodes {false}
 Determines whether to use nodes for the contact solver.
 
int surface_node_num {1000}
 Number of nodes used for the contact solver.
 
double surface_node_spacing {std::sqrt(Math::PI / 1000.0)}
 Spacing between nodes used for the contact solver.
 
VecXT< Vec3dsurface_nodes
 Surface nodes of the shape instance used for the contact solver.
 
VecXT< double > surface_node_areas
 Area associated with each surface node.
 

Detailed Description

A class representing a triangle in 3D space.

This class provides methods for generating, initializing, and computing operations on a Triangle object. The object is defined by its three vertices, and provides methods for computing signed distance, surface point, and generating an STL model. It also provides various options for calculating the support points of the triangle.

Examples
blade_mixing_main.cpp, and landslide_main.cpp.

Constructor & Destructor Documentation

◆ Triangle() [1/2]

Triangle::Triangle ( )

Default constructor.

◆ Triangle() [2/2]

Triangle::Triangle ( Vec3d const & a,
Vec3d const & b,
Vec3d const & c )

Constructor with specified vertices.

Parameters
aThe first vertex of the triangle.
bThe second vertex of the triangle.
cThe third vertex of the triangle.

Member Function Documentation

◆ CheckEnclose()

bool Triangle::CheckEnclose ( Vec3d const & pos) const
overridevirtual

Check if a point is enclosed by the Triangle object.

This method checks whether a point is enclosed by the Triangle object (which is always false for a triangle).

Parameters
posThe point to check.
Returns
false, indicating that the point is not enclosed by the Triangle object.

Reimplemented from netdem::Shape.

◆ Clone()

Shape * Triangle::Clone ( ) const
overridevirtual

Clone the Triangle object.

This method creates a copy of the Triangle object.

Returns
A pointer to the cloned Triangle object.

Reimplemented from netdem::Shape.

◆ GetBoundAABB() [1/2]

tuple< Vec3d, Vec3d > Triangle::GetBoundAABB ( ) const
overridevirtual

Compute the axis-aligned bounding box of the Triangle object.

This method computes the axis-aligned bounding box (AABB) of the Triangle object, relative to a specified position and orientation.

Returns
A tuple containing the minimum and maximum vertices of the AABB.

Reimplemented from netdem::Shape.

◆ GetBoundAABB() [2/2]

tuple< Vec3d, Vec3d > Triangle::GetBoundAABB ( Vec3d const & pos,
Vec4d const & quat ) const
overridevirtual

Compute the axis-aligned bounding box of the Triangle object.

This method computes the axis-aligned bounding box (AABB) of the Triangle object, relative to a specified position and orientation.

Parameters
posThe position vector of the AABB center.
quatThe orientation quaternion of the AABB.
Returns
A tuple containing the minimum and maximum vertices of the AABB.

Reimplemented from netdem::Shape.

◆ GetSTLModel()

STLModel Triangle::GetSTLModel ( int num_nodes = 200)
overridevirtual

Generate an STL model for the Triangle object.

This method generates an STLModel object representing the Triangle object with the specified number of nodes for each surface triangle.

Parameters
num_nodesThe number of nodes to use for each surface triangle (default: 200).
Returns
An STLModel object representing the Triangle object.

Reimplemented from netdem::Shape.

◆ Init()

void Triangle::Init ( )

Initialize the Triangle object.

This method initializes the Triangle object by updating its nodes and shape properties.

◆ InitFromJson()

void Triangle::InitFromJson ( nlohmann::json const & js)
overridevirtual

Initialize the Triangle object from a JSON structure.

This method initializes the Triangle object from a JSON structure previously generated by PackJson().

Parameters
jsThe JSON structure to load.

Reimplemented from netdem::Shape.

◆ PackJson()

nlohmann::json Triangle::PackJson ( )
overridevirtual

Pack the Triangle object into a JSON structure.

This method packs the Triangle object into a JSON structure for serialization and storage.

Returns
The packed JSON structure.

Reimplemented from netdem::Shape.

◆ SetVertices()

void Triangle::SetVertices ( Vec3d const & a,
Vec3d const & b,
Vec3d const & c )

Set the vertices of the Triangle object.

This method sets the vertices of the Triangle object to the specified vectors.

Parameters
aThe first vertex of the triangle.
bThe second vertex of the triangle.
cThe third vertex of the triangle.

◆ SignedDistance()

double Triangle::SignedDistance ( Vec3d const & pos) const
overridevirtual

Compute the signed distance between a point and the Triangle object.

This method computes the signed distance between a point and the Triangle object, which is positive if the point is outside the object and negative if it is inside.

Parameters
posThe point to compute the signed distance from.
Returns
The signed distance between the point and the Triangle object.

Reimplemented from netdem::Shape.

◆ SupportPoint()

Vec3d Triangle::SupportPoint ( Vec3d const & dir)
overridevirtual

Calculate the support point of the Triangle object in a given direction.

This method calculates the support point of the Triangle object in a given direction, which is the vertex that is farthest in that direction.

Parameters
dirThe direction vector to compute the support point for.
Returns
The support point of the Triangle object in the specified direction.

Reimplemented from netdem::Shape.

◆ SupportPoints()

VecXT< Vec3d > Triangle::SupportPoints ( Vec3d const & dir)
overridevirtual

Calculate the support points of the Triangle object in a given direction.

This method calculates the support points of the Triangle object in a given direction, which are the vertices that are farthest in that direction.

Parameters
dirThe direction vector to compute the support points for.
Returns
A vector containing the support points of the Triangle object in the specified direction.

Reimplemented from netdem::Shape.

◆ SurfacePoint()

Vec3d Triangle::SurfacePoint ( Vec3d const & pos)
overridevirtual

Compute the surface point of the Triangle object closest to a given point.

This method computes the surface point of the Triangle object closest to a given point using barycentric coordinates.

Parameters
posThe point to find the closest surface point to.
Returns
The surface point of the Triangle object closest to the specified point.

Reimplemented from netdem::Shape.

◆ Translate()

void Triangle::Translate ( Vec3d const & pos)
overridevirtual

Translate the Triangle object.

This method translates the Triangle object by the specified position vector.

Parameters
posThe position vector to translate the Triangle object by.

Reimplemented from netdem::Shape.

◆ UpdateShapeProperties()

void Triangle::UpdateShapeProperties ( )
overridevirtual

Update the shape properties of the Triangle object.

This method updates the shape properties of the Triangle object, such as its surface area and volume (which are both zero for a triangle).

Reimplemented from netdem::Shape.

◆ UpdateSurfaceNodes()

void Triangle::UpdateSurfaceNodes ( )
overridevirtual

Update the surface nodes of the Triangle object.

This method updates the surface nodes of the Triangle object based on its current position and orientation.

Reimplemented from netdem::Shape.

Member Data Documentation

◆ dir_n

Vec3d netdem::Triangle::dir_n {0, 0, 1}

The normal direction of the triangle.

◆ vertices

Mat3d netdem::Triangle::vertices

The three vertices that define the triangle.


The documentation for this class was generated from the following files: