IMP  2.2.0
The Integrative Modeling Platform
Plane3D.h
Go to the documentation of this file.
1 /**
2  * \file IMP/algebra/Plane3D.h \brief Simple 3D plane class.
3  *
4  * Copyright 2007-2014 IMP Inventors. All rights reserved.
5  *
6  */
7 
8 #ifndef IMPALGEBRA_PLANE_3D_H
9 #define IMPALGEBRA_PLANE_3D_H
10 
11 #include <IMP/algebra/algebra_config.h>
12 #include "Vector3D.h"
13 #include "BoundingBoxD.h"
14 #include "GeometricPrimitiveD.h"
15 
16 IMPALGEBRA_BEGIN_NAMESPACE
17 
18 /** Represent a plane in 3D.
19  \geometry
20 */
21 class Plane3D : public GeometricPrimitiveD<3> {
22  public:
23  Plane3D() {}
24  Plane3D(const Vector3D &point_on_plane, const Vector3D &normal_to_plane)
25  : normal_(normal_to_plane) {
26  distance_ = normal_ * point_on_plane;
27  IMP_USAGE_CHECK_FLOAT_EQUAL(normal_.get_squared_magnitude(), 1,
28  "The normal vector must be normalized");
29  }
30  Plane3D(double distance_to_plane, const Vector3D &normal_to_plane)
31  : distance_(distance_to_plane), normal_(normal_to_plane) {
32  IMP_USAGE_CHECK_FLOAT_EQUAL(normal_.get_squared_magnitude(), 1,
33  "The normal vector must be normalized");
34  }
35  Vector3D get_point_on_plane() const { return normal_ * distance_; }
36  const Vector3D &get_normal() const { return normal_; }
37  //! Project the point onto the plane
38  Vector3D get_projected(const Vector3D &p) const {
39  return p - normal_ * (normal_ * p - distance_);
40  }
41 #ifndef IMP_DOXYGEN
42  Vector3D get_projection(const Vector3D &p) const { return get_projected(p); }
43 #endif
44  /** @name Orientation
45  Up is the direction of the normal. You really shouldn't use
46  these as they aren't very reliable.
47  @{
48  */
49  bool get_is_above(const Vector3D &p) const { return get_height(p) > 0; }
50  bool get_is_below(const Vector3D &p) const { return get_height(p) < 0; }
51  /** @} */
52  double get_height(const Vector3D &p) const { return normal_ * p - distance_; }
53  IMP_SHOWABLE_INLINE(Plane3D,
54  { out << "(" << distance_ << ": " << spaces_io(normal_) << ")"; });
55 
56  //! Return the plane with the opposite normal
57  Plane3D get_opposite() const { return Plane3D(-distance_, -normal_); }
58  double get_distance_from_origin() const { return distance_; }
59 
60  private:
61  double distance_;
62  Vector3D normal_; // normal to plane
63 };
64 
65 //! Return the distance between a plane and a point in 3D
66 /** See Plane3D */
67 inline double get_distance(const Plane3D &pln, const Vector3D &p) {
68  return (pln.get_projection(p) - p).get_magnitude();
69 }
70 
71 //! return the point reflected about the plane
72 inline Vector3D get_reflected(const Plane3D &pln, const Vector3D &p) {
73  Vector3D proj = pln.get_projected(p);
74  return p + 2 * (proj - p);
75 }
76 
77 IMP_AREA_GEOMETRY_METHODS(Plane3D, plane_3d, IMP_UNUSED(g);
78  return std::numeric_limits<double>::infinity(), {
79  IMP_UNUSED(g);
80  Vector3D ip = get_ones_vector_d<3>(std::numeric_limits<double>::infinity());
81  return BoundingBoxD<3>(ip) + BoundingBox3D(-ip);
82 });
83 IMPALGEBRA_END_NAMESPACE
84 
85 #endif /* IMPALGEBRA_PLANE_3D_H */
Basic types used by IMP.
BoundingBoxD< 3 > BoundingBox3D
Definition: BoundingBoxD.h:160
void get_projection(em2d::Image *img, const kernel::ParticlesTemp &ps, const RegistrationResult &reg, const ProjectingOptions &options, MasksManagerPtr masks=MasksManagerPtr(), String name="")
Generates a projection from particles.
#define IMP_UNUSED(variable)
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
Vector3D get_reflected(const Plane3D &pln, const Vector3D &p)
return the point reflected about the plane
Definition: Plane3D.h:72
#define IMP_USAGE_CHECK_FLOAT_EQUAL(expra, exprb, message)
#define IMP_AREA_GEOMETRY_METHODS(Name, name, area, bounding_box)
implement the needed namespace methods for a geometry type
double get_distance(const Plane3D &pln, const Vector3D &p)
Return the distance between a plane and a point in 3D.
Definition: Plane3D.h:67
Plane3D get_opposite() const
Return the plane with the opposite normal.
Definition: Plane3D.h:57
A bounding box in D dimensions.
VectorD< 3 > Vector3D
Definition: VectorD.h:395
Simple 3D vector class.
Vector3D get_projected(const Vector3D &p) const
Project the point onto the plane.
Definition: Plane3D.h:38