IMP logo
IMP Reference Guide  develop.eb1b99edaa,2026/06/22
The Integrative Modeling Platform
Triangle3D.h
Go to the documentation of this file.
1 /**
2  * \file IMP/algebra/Triangle3D.h
3  * \brief Represent a triangle in 3D
4  *
5  * Copyright 2007-2026 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPALGEBRA_TRIANGLE_3D_H
9 #define IMPALGEBRA_TRIANGLE_3D_H
10 
11 #include "Vector3D.h"
12 #include "Transformation3D.h"
13 #include "ReferenceFrame3D.h"
15 #include <iostream>
16 #include <cereal/access.hpp>
17 #include "constants.h"
18 
19 IMPALGEBRA_BEGIN_NAMESPACE
20 
21 //! Represent a triangle in 3D
22 /** \geometry */
23 class IMPALGEBRAEXPORT Triangle3D : public GeometricPrimitiveD<3> {
24  public:
25  Triangle3D() {}
26  //! The passed points must not be colinear
27  Triangle3D(const Vector3D &p1, const Vector3D &p2, const Vector3D &p3);
28  //! Get the start=0/end=1 point of the segment
29  const Vector3D &get_point(unsigned int i) const {
30  IMP_USAGE_CHECK(i < 3, "invalid point index");
31  return p_[i];
32  }
33  IMP_SHOWABLE_INLINE(Triangle3D, out << "(" << p_[0] << ", " << p_[1] << ", "
34  << p_[2] << ")");
35  Floats get_edge_lengths() const;
36 
37 private:
38  Vector3D p_[3];
39 
40  friend class cereal::access;
41 
42  template<class Archive> void serialize(Archive &ar) {
43  ar(p_[0], p_[1], p_[2]);
44  }
45 };
46 
48 
49 //! Return the largest triangle defined by 3 points from the input
50 /** \see Triangle3D */
51 IMPALGEBRAEXPORT Triangle3D get_largest_triangle(const Vector3Ds &points);
52 
53 //! Return a transformation between two triangles
54 IMPALGEBRAEXPORT Transformation3D
56  Triangle3D second_tri);
57 //! Return true if the three points are co-linear
58 IMPALGEBRAEXPORT bool get_are_colinear(const Vector3D &p1, const Vector3D &p2,
59  const Vector3D &p3);
60 
61 IMPALGEBRA_END_NAMESPACE
62 
63 #endif /* IMPALGEBRA_TRIANGLE_3D_H */
Base class for geometric types.
Simple 3D transformation class.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
Triangle3D get_largest_triangle(const Vector3Ds &points)
Return the largest triangle defined by 3 points from the input.
Transformation3D get_transformation_from_first_triangle_to_second(Triangle3D first_tri, Triangle3D second_tri)
Return a transformation between two triangles.
Represent a triangle in 3D.
Definition: Triangle3D.h:23
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
Definition: value_macros.h:23
VectorD< 3 > Vector3D
Definition: VectorD.h:407
bool get_are_colinear(const Vector3D &p1, const Vector3D &p2, const Vector3D &p3)
Return true if the three points are co-linear.
Base class for geometric types.
Simple 3D vector class.
Various useful constants.
Simple 3D transformation class.
Vector< VectorD< 3 > > Vector3Ds
Definition: VectorD.h:409
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Definition: check_macros.h:168
A reference frame in 3D.
const Vector3D & get_point(unsigned int i) const
Get the start=0/end=1 point of the segment.
Definition: Triangle3D.h:29