IMP logo
IMP Reference Guide  2.7.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-2017 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  /** @name Orientation
41  Up is the direction of the normal. You really shouldn't use
42  these as they aren't very reliable.
43  @{
44  */
45  bool get_is_above(const Vector3D &p) const { return get_height(p) > 0; }
46  bool get_is_below(const Vector3D &p) const { return get_height(p) < 0; }
47  /** @} */
48  double get_height(const Vector3D &p) const { return normal_ * p - distance_; }
49  IMP_SHOWABLE_INLINE(Plane3D,
50  { out << "(" << distance_ << ": " << spaces_io(normal_) << ")"; });
51 
52  //! Return the plane with the opposite normal
53  Plane3D get_opposite() const { return Plane3D(-distance_, -normal_); }
54  double get_distance_from_origin() const { return distance_; }
55 
56  private:
57  double distance_;
58  Vector3D normal_; // normal to plane
59 };
60 
61 //! Return the distance between a plane and a point in 3D
62 /** \see Plane3D */
63 inline double get_distance(const Plane3D &pln, const Vector3D &p) {
64  return (pln.get_projected(p) - p).get_magnitude();
65 }
66 
67 //! Return the point reflected about the plane
68 inline Vector3D get_reflected(const Plane3D &pln, const Vector3D &p) {
69  Vector3D proj = pln.get_projected(p);
70  return p + 2 * (proj - p);
71 }
72 
73 IMP_AREA_GEOMETRY_METHODS(Plane3D, plane_3d, IMP_UNUSED(g);
74  return std::numeric_limits<double>::infinity(), {
75  IMP_UNUSED(g);
76  Vector3D ip = get_ones_vector_d<3>(std::numeric_limits<double>::infinity());
77  return BoundingBoxD<3>(ip) + BoundingBox3D(-ip);
78 });
79 IMPALGEBRA_END_NAMESPACE
80 
81 #endif /* IMPALGEBRA_PLANE_3D_H */
Base class for geometric types.
double get_height(const Surface &s, const XYZR &d)
Get height of sphere above surface.
Definition: Surface.h:127
#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:176
#define IMP_USAGE_CHECK_FLOAT_EQUAL(expra, exprb, message)
Definition: check_macros.h:178
Vector3D get_reflected(const Plane3D &pln, const Vector3D &p)
Return the point reflected about the plane.
Definition: Plane3D.h:68
#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:63
#define IMP_UNUSED(variable)
Plane3D get_opposite() const
Return the plane with the opposite normal.
Definition: Plane3D.h:53
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