10 #include <Moby/Constants.h>
11 #include <Moby/Triangle.h>
12 #include <Ravelin/Vector3d.h>
21 Plane(
double nx,
double ny,
double nz,
double d) { _normal = Ravelin::Vector3d(nx, ny, nz); _normal.normalize();
offset = d; }
22 Plane(
const Triangle& t) { _normal = t.calc_normal();
offset = t.calc_offset(_normal); }
23 Plane(
const Ravelin::Vector3d& n,
double d) { _normal = Ravelin::Vector3d::normalize(n);
offset = d; }
24 Plane(
const Ravelin::Vector3d& normal,
const Point3d& point) { _normal = Ravelin::Vector3d::normalize(normal);
offset = normal.dot(point); }
27 double calc_signed_distance(
const Point3d& p)
const {
return _normal.dot(p) -
offset; }
28 bool on_plane(
const Point3d& p) {
return std::fabs(calc_signed_distance(p)) < NEAR_ZERO * std::max((
double) 1.0, std::max(p.norm_inf(), std::fabs(
offset))); }
29 bool operator==(
const Plane& p)
const {
double dot = _normal.dot(p.
get_normal());
return (std::fabs(dot - 1.0) < NEAR_ZERO && std::fabs(
offset - p.
offset) < NEAR_ZERO); }
30 bool operator<(
const Plane& p)
const;
31 boost::shared_ptr<const Ravelin::Pose3d> get_pose()
const {
return _normal.pose; }
40 const Ravelin::Vector3d&
get_normal()
const {
return _normal; }
43 void set_normal(
const Ravelin::Vector3d& n) { _normal = Ravelin::Vector3d::normalize(n); }
49 Ravelin::Vector3d _normal;
59 p._normal = T.transform_vector(_normal);
66 Point3d new_plane_point = T.transform_point(plane_point);
69 p.
offset = p._normal.dot(new_plane_point);
77 const unsigned X = 0, Y = 1, Z = 2;
80 Ravelin::Vector3d v1, v2;
81 Ravelin::Vector3d::determine_orthonormal_basis(_normal, v1, v2);
83 R.set_row(X, Ravelin::Origin3d(v1));
84 R.set_row(Y, Ravelin::Origin3d(v2));
85 R.set_row(Z, Ravelin::Origin3d(_normal));
88 Ravelin::Origin3d result = R * Ravelin::Origin3d(p);
90 return Ravelin::Origin2d(result[X], result[Y]);
96 double d = _normal.dot(p);
100 inline bool Plane::operator<(
const Plane& p)
const
102 const unsigned X = 0, Y = 1, Z = 2;
122 inline std::ostream& operator<<(std::ostream& out,
const Plane& p)
124 out <<
"normal: " << p.get_normal() <<
" offset: " << p.offset;
Plane operator-() const
Assuming this plane represents a half-space, negates the half-space.
Definition: Plane.h:37
Point3d project(const Point3d &p) const
Projects a point onto the plane.
Definition: Plane.h:94
const Ravelin::Vector3d & get_normal() const
Gets the outward pointing normal to the plane.
Definition: Plane.h:40
Defines a plane using the equation <n, x> = d.
Definition: Plane.h:17
Ravelin::Origin2d to_2D(const Point3d &p) const
Transforms a point to 2D.
Definition: Plane.h:75
Plane transform(const Ravelin::Transform3d &T) const
Transforms a plane.
Definition: Plane.h:53
double offset
The plane offset such that the plane equation is given by <n, x> = offset.
Definition: Plane.h:46
Ravelin::Vector3d Point3d
Typedef to distinguish between a 3D vector and a point.
Definition: Types.h:47
void set_normal(const Ravelin::Vector3d &n)
Sets the outward pointing normal to the plane.
Definition: Plane.h:43