IMP  2.3.1
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 class Plane3D : public GeometricPrimitiveD<3> {
21  public:
22  Plane3D() {}
23  Plane3D(const Vector3D &point_on_plane, const Vector3D &normal_to_plane)
24  : normal_(normal_to_plane) {
25  distance_ = normal_ * point_on_plane;
26  IMP_USAGE_CHECK_FLOAT_EQUAL(normal_.get_squared_magnitude(), 1,
27  "The normal vector must be normalized");
28  }
29  Plane3D(double distance_to_plane, const Vector3D &normal_to_plane)
30  : distance_(distance_to_plane), normal_(normal_to_plane) {
31  IMP_USAGE_CHECK_FLOAT_EQUAL(normal_.get_squared_magnitude(), 1,
32  "The normal vector must be normalized");
33  }
34  Vector3D get_point_on_plane() const { return normal_ * distance_; }
35  const Vector3D &get_normal() const { return normal_; }
36  //! Project the point onto the plane
37  Vector3D get_projected(const Vector3D &p) const {
38  return p - normal_ * (normal_ * p - distance_);
39  }
40 #ifndef IMP_DOXYGEN
41  /** \deprecated_at{2.3} Use get_projected() instead. */
42  IMPALGEBRA_DEPRECATED_METHOD_DECL(2.3)
43  Vector3D get_projection(const Vector3D &p) const {
44  IMPALGEBRA_DEPRECATED_METHOD_DEF(2.3, "Use get_projected() instead.");
45  return get_projected(p);
46  }
47 #endif
48  /** @name Orientation
49  Up is the direction of the normal. You really shouldn't use
50  these as they aren't very reliable.
51  @{
52  */
53  bool get_is_above(const Vector3D &p) const { return get_height(p) > 0; }
54  bool get_is_below(const Vector3D &p) const { return get_height(p) < 0; }
55  /** @} */
56  double get_height(const Vector3D &p) const { return normal_ * p - distance_; }
57  IMP_SHOWABLE_INLINE(Plane3D,
58  { out << "(" << distance_ << ": " << spaces_io(normal_) << ")"; });
59 
60  //! Return the plane with the opposite normal
61  Plane3D get_opposite() const { return Plane3D(-distance_, -normal_); }
62  double get_distance_from_origin() const { return distance_; }
63 
64  private:
65  double distance_;
66  Vector3D normal_; // normal to plane
67 };
68 
69 //! Return the distance between a plane and a point in 3D
70 /** \see Plane3D */
71 inline double get_distance(const Plane3D &pln, const Vector3D &p) {
72  return (pln.get_projection(p) - p).get_magnitude();
73 }
74 
75 //! Return the point reflected about the plane
76 inline Vector3D get_reflected(const Plane3D &pln, const Vector3D &p) {
77  Vector3D proj = pln.get_projected(p);
78  return p + 2 * (proj - p);
79 }
80 
81 IMP_AREA_GEOMETRY_METHODS(Plane3D, plane_3d, IMP_UNUSED(g);
82  return std::numeric_limits<double>::infinity(), {
83  IMP_UNUSED(g);
84  Vector3D ip = get_ones_vector_d<3>(std::numeric_limits<double>::infinity());
85  return BoundingBoxD<3>(ip) + BoundingBox3D(-ip);
86 });
87 IMPALGEBRA_END_NAMESPACE
88 
89 #endif /* IMPALGEBRA_PLANE_3D_H */
Basic types used by IMP.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
BoundingBoxD< 3 > BoundingBox3D
Typedef for Python.
Definition: BoundingBoxD.h:160
#define IMP_USAGE_CHECK_FLOAT_EQUAL(expra, exprb, message)
Definition: check_macros.h:180
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.
Vector3D get_reflected(const Plane3D &pln, const Vector3D &p)
Return the point reflected about the plane.
Definition: Plane3D.h:76
#define IMP_AREA_GEOMETRY_METHODS(Name, name, area, bounding_box)
Implement the needed namespace methods for a geometry type.
Base class for geometric types.
double get_distance(const Plane3D &pln, const Vector3D &p)
Return the distance between a plane and a point in 3D.
Definition: Plane3D.h:71
#define IMP_UNUSED(variable)
Plane3D get_opposite() const
Return the plane with the opposite normal.
Definition: Plane3D.h:61
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:37
Represent a plane in 3D.
Definition: Plane3D.h:20