IMP logo
IMP Reference Guide  2.22.0
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-2022 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"
14 #include "algebra_macros.h"
15 #include "GeometricPrimitiveD.h"
16 #include <iostream>
17 #include <cereal/access.hpp>
18 #include "constants.h"
19 
20 IMPALGEBRA_BEGIN_NAMESPACE
21 
22 //! Represent a triangle in 3D
23 /** \geometry */
24 class IMPALGEBRAEXPORT Triangle3D : public GeometricPrimitiveD<3> {
25  public:
26  Triangle3D() {}
27  //! The passed points must not be colinear
28  Triangle3D(const Vector3D &p1, const Vector3D &p2, const Vector3D &p3);
29  //! Get the start=0/end=1 point of the segment
30  const Vector3D &get_point(unsigned int i) const {
31  IMP_USAGE_CHECK(i < 3, "invalid point index");
32  return p_[i];
33  }
34  IMP_SHOWABLE_INLINE(Triangle3D, out << "(" << p_[0] << ", " << p_[1] << ", "
35  << p_[2] << ")");
36  Floats get_edge_lengths() const;
37 
38 private:
39  Vector3D p_[3];
40 
41  friend class cereal::access;
42 
43  template<class Archive> void serialize(Archive &ar) {
44  ar(p_[0], p_[1], p_[2]);
45  }
46 };
47 
49 
50 //! Return the largest triangle defined by 3 points from the input
51 /** \see Triangle3D */
52 IMPALGEBRAEXPORT Triangle3D get_largest_triangle(const Vector3Ds &points);
53 
54 //! Return a transformation between two triangles
55 IMPALGEBRAEXPORT Transformation3D
57  Triangle3D second_tri);
58 //! Return true if the three points are co-linear
59 IMPALGEBRAEXPORT bool get_are_colinear(const Vector3D &p1, const Vector3D &p2,
60  const Vector3D &p3);
61 
62 IMPALGEBRA_END_NAMESPACE
63 
64 #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:24
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
Definition: value_macros.h:23
Base class for geometric types.
bool get_are_colinear(const Vector3D &p1, const Vector3D &p2, const Vector3D &p3)
Return true if the three points are co-linear.
Various useful constants.
Simple 3D transformation class.
VectorD< 3 > Vector3D
Definition: VectorD.h:408
Simple 3D vector class.
#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:30
Various helper macros.