IMP logo
IMP Reference Guide  2.20.0
The Integrative Modeling Platform
Line3D.h
Go to the documentation of this file.
1 /**
2  * \file IMP/algebra/Line3D.h
3  * \brief Simple implementation of lines in 3D
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPALGEBRA_LINE_3D_H
9 #define IMPALGEBRA_LINE_3D_H
10 
11 #include <IMP/algebra/algebra_config.h>
12 #include "Vector3D.h"
13 #include "Segment3D.h"
14 #include "BoundingBoxD.h"
15 #include "algebra_macros.h"
16 #include "GeometricPrimitiveD.h"
17 #include <cereal/access.hpp>
18 
19 IMPALGEBRA_BEGIN_NAMESPACE
20 //! Simple implementation of lines in 3D
21 /** A line is defined by a direction and any point on the
22  line. Internally, Plucker coordinates are used, where
23  the line is defined by a direction and an orthogonal
24  moment about the origin whose magnitude is the
25  distance from the origin.
26  \geometry
27  \see Segment3D
28  */
29 class IMPALGEBRAEXPORT Line3D : public GeometricPrimitiveD<3> {
30  Vector3D l_, m_;
31 
32  friend class cereal::access;
33 
34  template<class Archive> void serialize(Archive &ar) {
35  ar(l_, m_);
36  }
37 
38  public:
39  Line3D() {}
40  Line3D(const Vector3D &direction, const Vector3D &point_on_line);
41  //! Create line along segment.
42  Line3D(const algebra::Segment3D &s);
43 
44  //! Get the unit vector in the direction of the line.
45  const Vector3D& get_direction() const { return l_; }
46 
47  //! Get the point on the line closest to the origin.
48  Vector3D get_point_on_line() const { return get_vector_product(l_, m_); }
49 
50  //! Get the moment of the line about the origin.
51  Vector3D get_moment() const { return m_; }
52 
53  //! Get the moment of the line about a point.
54  Vector3D get_moment(const Vector3D &v) const {
55  return m_ - get_vector_product(v, l_);
56  }
57 
58  //! Get reciprocal (or virtual) product, the moment of either line about the other.
59  double get_reciprocal_product(const Line3D &l) const;
60 
61  //! Get the line in the opposite direction.
62  Line3D get_opposite() const { return Line3D(-l_, get_point_on_line()); }
63 
64  //! Get segment of a given length starting at a point.
65  /** \note The point is not assumed to be on the line and is therefore
66  projected onto the line to construct the segment.
67  */
68  algebra::Segment3D get_segment_starting_at(const Vector3D &v, double d) const;
69 
71  { out << "[" << l_ << " ; " << m_ << "]"; });
72 };
73 
74 IMP_LINEAR_GEOMETRY_METHODS(Line3D, line_3d,
75  Vector3D pop = g.get_point_on_line();
76  return BoundingBoxD<3>(pop) +
77  BoundingBoxD<3>(pop + g.get_direction()));
78 
79 //! Project a point onto the line.
80 /** This is equivalent to the point on the line closest to the
81  provided point.
82 */
83 IMPALGEBRAEXPORT Vector3D get_projected(const Line3D &l, const Vector3D &p);
84 
85 //! Project a segment onto a line.
86 IMPALGEBRAEXPORT algebra::Segment3D get_projected(const Line3D &l,
87  const algebra::Segment3D &s);
88 
89 //! Get closest distance between a line and a point.
90 IMPALGEBRAEXPORT double get_distance(const Line3D &s, const Vector3D &p);
91 
92 //! Get angle in radians between two lines around their closest points.
93 IMPALGEBRAEXPORT double get_angle(const Line3D &a, const Line3D &b);
94 
95 //! Get the closest distance between two lines.
96 IMPALGEBRAEXPORT double get_distance(const Line3D &a, const Line3D &b);
97 
98 //! Get shortest possible segment from the first line to the second.
99 /** \note If the lines are parallel, this segment is not unique and is chosen
100 // so that the segment passes closest to the origin.*/
102  const Line3D &a, const Line3D &b);
103 
104 IMPALGEBRA_END_NAMESPACE
105 
106 #endif /* IMPALGEBRA_LINE_3D_H */
algebra::Segment3D get_projected(const Line3D &l, const algebra::Segment3D &s)
Project a segment onto a line.
Base class for geometric types.
Simple implementation of lines in 3D.
Definition: Line3D.h:29
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
#define IMP_LINEAR_GEOMETRY_METHODS(Name, name, bounding_box)
Implement the needed namespace methods for a geometry type.
Line3D get_opposite() const
Get the line in the opposite direction.
Definition: Line3D.h:62
Vector3D get_point_on_line() const
Get the point on the line closest to the origin.
Definition: Line3D.h:48
double get_angle(const Line3D &a, const Line3D &b)
Get angle in radians between two lines around their closest points.
Simple implementation of segments in 3D.
double get_distance(const Line3D &a, const Line3D &b)
Get the closest distance between two lines.
Vector3D get_moment() const
Get the moment of the line about the origin.
Definition: Line3D.h:51
Base class for geometric types.
Vector3D get_vector_product(const Vector3D &p1, const Vector3D &p2)
Return the vector product (cross product) of two vectors.
Definition: Vector3D.h:31
A bounding box in D dimensions.
Simple implementation of segments in 3D.
Definition: Segment3D.h:25
const Vector3D & get_direction() const
Get the unit vector in the direction of the line.
Definition: Line3D.h:45
VectorD< 3 > Vector3D
Definition: VectorD.h:425
Simple 3D vector class.
algebra::Segment3D get_segment_connecting_first_to_second(const Line3D &a, const Line3D &b)
Get shortest possible segment from the first line to the second.
Various helper macros.
Vector3D get_moment(const Vector3D &v) const
Get the moment of the line about a point.
Definition: Line3D.h:54