IMP logo
IMP Reference Guide  develop.eb1b99edaa,2026/06/25
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-2026 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"
16 #include <cereal/access.hpp>
17 
18 IMPALGEBRA_BEGIN_NAMESPACE
19 //! Simple implementation of lines in 3D
20 /** A line is defined by a direction and any point on the
21  line. Internally, Plucker coordinates are used, where
22  the line is defined by a direction and an orthogonal
23  moment about the origin whose magnitude is the
24  distance from the origin.
25  \geometry
26  \see Segment3D
27  */
28 class IMPALGEBRAEXPORT Line3D : public GeometricPrimitiveD<3> {
29  Vector3D l_, m_;
30 
31  friend class cereal::access;
32 
33  template<class Archive> void serialize(Archive &ar) {
34  ar(l_, m_);
35  }
36 
37  public:
38  Line3D() {}
39  Line3D(const Vector3D &direction, const Vector3D &point_on_line);
40  //! Create line along segment.
41  Line3D(const algebra::Segment3D &s);
42 
43  //! Get the unit vector in the direction of the line.
44  const Vector3D& get_direction() const { return l_; }
45 
46  //! Get the point on the line closest to the origin.
47  Vector3D get_point_on_line() const { return get_vector_product(l_, m_); }
48 
49  //! Get the moment of the line about the origin.
50  Vector3D get_moment() const { return m_; }
51 
52  //! Get the moment of the line about a point.
53  Vector3D get_moment(const Vector3D &v) const {
54  return m_ - get_vector_product(v, l_);
55  }
56 
57  //! Get reciprocal (or virtual) product, the moment of either line about the other.
58  double get_reciprocal_product(const Line3D &l) const;
59 
60  //! Get the line in the opposite direction.
61  Line3D get_opposite() const { return Line3D(-l_, get_point_on_line()); }
62 
63  //! Get segment of a given length starting at a point.
64  /** \note The point is not assumed to be on the line and is therefore
65  projected onto the line to construct the segment.
66  */
67  algebra::Segment3D get_segment_starting_at(const Vector3D &v, double d) const;
68 
70  { out << "[" << l_ << " ; " << m_ << "]"; });
71 };
72 
73 IMP_LINEAR_GEOMETRY_METHODS(Line3D, line_3d,
74  Vector3D pop = g.get_point_on_line();
75  return BoundingBoxD<3>(pop) +
76  BoundingBoxD<3>(pop + g.get_direction()));
77 
78 //! Project a point onto the line.
79 /** This is equivalent to the point on the line closest to the
80  provided point.
81 */
82 IMPALGEBRAEXPORT Vector3D get_projected(const Line3D &l, const Vector3D &p);
83 
84 //! Project a segment onto a line.
85 IMPALGEBRAEXPORT algebra::Segment3D get_projected(const Line3D &l,
86  const algebra::Segment3D &s);
87 
88 //! Get closest distance between a line and a point.
89 IMPALGEBRAEXPORT double get_distance(const Line3D &s, const Vector3D &p);
90 
91 //! Get angle in radians between two lines around their closest points.
92 IMPALGEBRAEXPORT double get_angle(const Line3D &a, const Line3D &b);
93 
94 //! Get the closest distance between two lines.
95 IMPALGEBRAEXPORT double get_distance(const Line3D &a, const Line3D &b);
96 
97 //! Get shortest possible segment from the first line to the second.
98 /** \note If the lines are parallel, this segment is not unique and is chosen
99 // so that the segment passes closest to the origin.*/
101  const Line3D &a, const Line3D &b);
102 
103 IMPALGEBRA_END_NAMESPACE
104 
105 #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:28
#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:61
Vector3D get_point_on_line() const
Get the point on the line closest to the origin.
Definition: Line3D.h:47
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:50
VectorD< 3 > Vector3D
Definition: VectorD.h:407
A bounding box in D dimensions.
Base class for geometric types.
Simple 3D vector class.
Simple implementation of segments in 3D.
Definition: Segment3D.h:24
const Vector3D & get_direction() const
Get the unit vector in the direction of the line.
Definition: Line3D.h:44
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.
Vector3D get_vector_product(const Vector3D &p1, const Vector3D &p2)
Return the vector product (cross product) of two vectors.
Definition: Vector3D.h:31
Vector3D get_moment(const Vector3D &v) const
Get the moment of the line about a point.
Definition: Line3D.h:53