IMP  2.0.0
The Integrative Modeling Platform
Segment3D.h
Go to the documentation of this file.
1 /**
2  * \file IMP/algebra/Segment3D.h
3  * \brief simple implementation of segments in 3D
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPALGEBRA_SEGMENT_3D_H
9 #define IMPALGEBRA_SEGMENT_3D_H
10 
11 #include <IMP/algebra/algebra_config.h>
12 #include "Vector3D.h"
13 #include "BoundingBoxD.h"
14 #include "algebra_macros.h"
15 #include "GeometricPrimitiveD.h"
16 #include <iostream>
17 #include "constants.h"
18 
19 
20 IMPALGEBRA_BEGIN_NAMESPACE
21 /** It does what is says.
22  \geometry
23  */
24 class IMPALGEBRAEXPORT Segment3D: public GeometricPrimitiveD<3>
25 {
26  public:
27  Segment3D(){}
28  Segment3D(const Vector3D &start,const Vector3D &end);
29  //! Get the start=0/end=1 point of the segment
30  const Vector3D& get_point(unsigned int i) const {
31 #if defined(IMP_SWIG_WRAPPER)
32  IMP_USAGE_CHECK(i<2,"invalid point index");
33 #else
34  IMP_INTERNAL_CHECK(i<2, "Invalid point index");
35 #endif
36  return p_[i];
37  }
38  Vector3D get_middle_point() const {
39  return .5*p_[0]+ .5*p_[1];
40  }
41  /** \brief Get a normalized direction vector pointing from
42  get_point(0) to get_point(1).
43  */
44  Vector3D get_direction() const {return (p_[1]-p_[0]).get_unit_vector();}
45  double get_length() const;
47  {out << spaces_io(p_[0]) << ": " << spaces_io(p_[1]);});
48  private:
49  Vector3D p_[2];
50 };
51 
52 IMP_LINEAR_GEOMETRY_METHODS(Segment3D, segment_3d,
53  return BoundingBoxD<3>(g.get_point(0))
54  +BoundingBoxD<3>(g.get_point(1)));
55 
56 
57 /** Returns f, the 'relative' projection of a point p onto the line
58  that contains s.
59  Formally, the projection of p onto the line through s is s[0]+f*(s[1]-s[0])
60  f is in the range [0..1] if the projection of p is inside s.
61 
62  @param s segment in 3D
63  @param p point in 3D
64 
65  @return the 'relative' project of p onto the line containing s
66 */
67 IMPALGEBRAEXPORT double
69 (const Segment3D &s,
70  const algebra::Vector3D &p);
71 
72 //! Get the distance between a segment and a point
73 /** \relatesalso Segment3D */
74 IMPALGEBRAEXPORT double get_distance(const Segment3D &s, const Vector3D &p);
75 
76 //! Get the distance between two segments
77 /** \relatesalso Segment3D */
78 IMPALGEBRAEXPORT double get_distance(const Segment3D &a, const Segment3D &b);
79 
80 
81 IMPALGEBRA_END_NAMESPACE
82 
83 #endif /* IMPALGEBRA_SEGMENT_3D_H */