IMP  2.1.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 IMPALGEBRA_BEGIN_NAMESPACE
20 /** It does what is says.
21  \geometry
22  */
23 class IMPALGEBRAEXPORT Segment3D : public GeometricPrimitiveD<3> {
24  public:
25  Segment3D() {}
26  Segment3D(const Vector3D &start, const Vector3D &end);
27  //! Get the start=0/end=1 point of the segment
28  const Vector3D &get_point(unsigned int i) const {
29 #if defined(IMP_SWIG_WRAPPER)
30  IMP_USAGE_CHECK(i < 2, "invalid point index");
31 #else
32  IMP_INTERNAL_CHECK(i < 2, "Invalid point index");
33 #endif
34  return p_[i];
35  }
36  Vector3D get_middle_point() const { return .5 * p_[0] + .5 * p_[1]; }
37  /** \brief Get a normalized direction vector pointing from
38  get_point(0) to get_point(1).
39  */
40  Vector3D get_direction() const { return (p_[1] - p_[0]).get_unit_vector(); }
41  double get_length() const;
43  { out << spaces_io(p_[0]) << ": " << spaces_io(p_[1]); });
44 
45  private:
46  Vector3D p_[2];
47 };
48 
50  Segment3D, segment_3d,
51  return BoundingBoxD<3>(g.get_point(0)) + BoundingBoxD<3>(g.get_point(1)));
52 
53 /** Returns f, the 'relative' projection of a point p onto the line
54  that contains s.
55  Formally, the projection of p onto the line through s is s[0]+f*(s[1]-s[0])
56  f is in the range [0..1] if the projection of p is inside s.
57 
58  @param s segment in 3D
59  @param p point in 3D
60 
61  @return the 'relative' project of p onto the line containing s
62 */
63 IMPALGEBRAEXPORT double get_relative_projection_on_segment(
64  const Segment3D &s, const algebra::Vector3D &p);
65 
66 //! Get the distance between a segment and a point
67 /** See Segment3D */
68 IMPALGEBRAEXPORT double get_distance(const Segment3D &s, const Vector3D &p);
69 
70 //! Get the distance between two segments
71 /** See Segment3D */
72 IMPALGEBRAEXPORT double get_distance(const Segment3D &a, const Segment3D &b);
73 
74 IMPALGEBRA_END_NAMESPACE
75 
76 #endif /* IMPALGEBRA_SEGMENT_3D_H */
Basic types used by IMP.
#define IMP_LINEAR_GEOMETRY_METHODS(Name, name, bounding_box)
implement the needed namespace methods for a geometry type
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
double get_distance(const Plane3D &pln, const Vector3D &p)
Return the distance between a plane and a point in 3D.
Definition: Plane3D.h:68
Vector3D get_direction() const
Get a normalized direction vector pointing from get_point(0) to get_point(1).
Definition: Segment3D.h:40
#define IMP_INTERNAL_CHECK(expr, message)
An assertion to check for internal errors in IMP. An IMP::ErrorException will be thrown.
A bounding box in D dimensions.
Various useful constants.
double get_relative_projection_on_segment(const Segment3D &s, const algebra::Vector3D &p)
VectorD< 3 > Vector3D
Definition: VectorD.h:587
Simple 3D vector class.
VectorD get_unit_vector() const
Definition: VectorD.h:204
Various important macros for implementing geometry.
const Vector3D & get_point(unsigned int i) const
Get the start=0/end=1 point of the segment.
Definition: Segment3D.h:28