IMP logo
IMP Reference Guide  develop.d247202c1c,2019/10/23
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-2019 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 
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  public:
32  Line3D() {}
33  Line3D(const Vector3D &direction, const Vector3D &point_on_line);
34  //! Create line along segment.
35  Line3D(const algebra::Segment3D &s);
36 
37  //! Get the unit vector in the direction of the line.
38  const Vector3D& get_direction() const { return l_; }
39 
40  //! Get the point on the line closest to the origin.
41  Vector3D get_point_on_line() const { return get_vector_product(l_, m_); }
42 
43  //! Get the moment of the line about the origin.
44  Vector3D get_moment() const { return m_; }
45 
46  //! Get the moment of the line about a point.
47  Vector3D get_moment(const Vector3D &v) const {
48  return m_ - get_vector_product(v, l_);
49  }
50 
51  //! Get reciprocal (or virtual) product, the moment of either line about the other.
52  double get_reciprocal_product(const Line3D &l) const;
53 
54  //! Get the line in the opposite direction.
55  Line3D get_opposite() const { return Line3D(-l_, get_point_on_line()); }
56 
57  //! Get segment of a given length starting at a point.
58  /** \note The point is not assumed to be on the line and is therefore
59  projected onto the line to construct the segment.
60  */
61  algebra::Segment3D get_segment_starting_at(const Vector3D &v, double d) const;
62 
64  { out << "[" << l_ << " ; " << m_ << "]"; });
65 };
66 
67 IMP_LINEAR_GEOMETRY_METHODS(Line3D, line_3d,
68  Vector3D pop = g.get_point_on_line();
69  return BoundingBoxD<3>(pop) +
70  BoundingBoxD<3>(pop + g.get_direction()));
71 
72 //! Project a point onto the line.
73 /** This is equivalent to the point on the line closest to the
74  provided point.
75 */
76 IMPALGEBRAEXPORT Vector3D get_projected(const Line3D &l, const Vector3D &p);
77 
78 //! Project a segment onto a line.
79 IMPALGEBRAEXPORT algebra::Segment3D get_projected(const Line3D &l,
80  const algebra::Segment3D &s);
81 
82 //! Get closest distance between a line and a point.
83 IMPALGEBRAEXPORT double get_distance(const Line3D &s, const Vector3D &p);
84 
85 //! Get angle in radians between two lines around their closest points.
86 IMPALGEBRAEXPORT double get_angle(const Line3D &a, const Line3D &b);
87 
88 //! Get the closest distance between two lines.
89 IMPALGEBRAEXPORT double get_distance(const Line3D &a, const Line3D &b);
90 
91 //! Get shortest possible segment from the first line to the second.
92 /** \note If the lines are parallel, this segment is not unique and is chosen
93 // so that the segment passes closest to the origin.*/
95  const Line3D &a, const Line3D &b);
96 
97 IMPALGEBRA_END_NAMESPACE
98 
99 #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:55
Vector3D get_point_on_line() const
Get the point on the line closest to the origin.
Definition: Line3D.h:41
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:44
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:24
const Vector3D & get_direction() const
Get the unit vector in the direction of the line.
Definition: Line3D.h:38
VectorD< 3 > Vector3D
Definition: VectorD.h:421
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:47