contrib/oxl/mvl/HomgPlane3D.cxx
Go to the documentation of this file.
00001 // This is oxl/mvl/HomgPlane3D.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 //  \file
00007 
00008 #include "HomgPlane3D.h"
00009 
00010 #include <vcl_iostream.h>
00011 #include <vnl/vnl_double_3.h>
00012 #include <mvl/Homg3D.h>
00013 #include <mvl/HomgPoint3D.h>
00014 
00015 
00016 //--------------------------------------------------------------
00017 //
00018 //: Constructor
00019 HomgPlane3D::HomgPlane3D ()
00020 {
00021 }
00022 
00023 //--------------------------------------------------------------
00024 //
00025 //: Constructor
00026 HomgPlane3D::HomgPlane3D (double x, double y, double z, double w)
00027     : Homg3D (x, y, z, w)
00028 {
00029 }
00030 
00031 //--------------------------------------------------------------
00032 //
00033 //: Constructor
00034 HomgPlane3D::HomgPlane3D (const vnl_double_3& n, double d)
00035   : Homg3D (n[0], n[1], n[2], -d)
00036 {
00037 }
00038 
00039 //--------------------------------------------------------------
00040 //
00041 //: Destructor
00042 HomgPlane3D::~HomgPlane3D ()
00043 {
00044 }
00045 
00046 //: closest point
00047 HomgPoint3D HomgPlane3D::closest_point(const HomgPoint3D& p) const
00048 {
00049   vnl_double_3 n(x(), y(), z());
00050 
00051   double s = 1.0/n.magnitude();
00052   double d = -w();
00053 
00054   n *= s;
00055   d *= s;
00056 
00057   vnl_double_3 x3 = p.get_double3();
00058 
00059   double dp = dot_product(x3, n) - d;
00060 
00061   vnl_double_3 px = x3 - dp * n;
00062 
00063   return HomgPoint3D(px[0], px[1], px[2], 1.0);
00064 }
00065 
00066 //: Distance point to plane
00067 double HomgPlane3D::distance(const HomgPoint3D& p) const
00068 {
00069   vnl_double_3 n(x(), y(), z());
00070 
00071   double s = 1.0/n.magnitude();
00072   double d = -w();
00073 
00074   vnl_double_3 x3 = p.get_double3();
00075 
00076   return (dot_product(x3, n) - d)*s;
00077 }
00078 
00079 //: print
00080 vcl_ostream& operator<<(vcl_ostream& s, const HomgPlane3D& P)
00081 {
00082   return s << P.get_vector();
00083 }