Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * hom_point.cpp - Homogenous point 00004 * 00005 * Created: Thu Sep 27 17:01:55 2007 00006 * Copyright 2007-2008 Daniel Beck 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 #include "hom_point.h" 00025 #include "hom_vector.h" 00026 #include <cmath> 00027 #include <cstdio> 00028 #include <exception> 00029 00030 namespace fawkes { 00031 00032 /** @class HomPoint geometry/hom_point.h 00033 * A homogeneous point. 00034 * @author Daniel Beck 00035 */ 00036 00037 /**Constructor. 00038 * @param x the x-coordinate 00039 * @param y the y-coordinate 00040 * @param z the z-coordinate 00041 */ 00042 HomPoint::HomPoint(float x, float y, float z) 00043 : HomCoord(x, y, z, 1.0) 00044 { 00045 } 00046 00047 /** Constructor. 00048 * Constructs a 2-dimensional vector from a cart_coord_2d_t struct. 00049 *@param coord a structure for a 2-dimensional coordinate 00050 */ 00051 HomPoint::HomPoint(cart_coord_2d_t coord) 00052 : HomCoord(coord.x, coord.y, 0.0, 1.0) 00053 { 00054 } 00055 00056 /** Constructor. 00057 * Constructs a 3-dimensional vector from a cart_coord_3d_t struct. 00058 *@param coord a structure for a 3-dimensional coordinate 00059 */ 00060 HomPoint::HomPoint(cart_coord_3d_t coord) 00061 : HomCoord(coord.x, coord.y, coord.z, 1.0) 00062 { 00063 } 00064 00065 /** Constructor. 00066 * @param h a HomCoord 00067 */ 00068 HomPoint::HomPoint(const HomCoord& h) 00069 : HomCoord(h) 00070 { 00071 if ( 1.0 != w() ) 00072 { 00073 printf("HomPoint(const HomCoord& h): The forth component of a " 00074 "homogeneous point has to be 1.0 but is %f\n", w()); 00075 throw std::exception(); 00076 } 00077 } 00078 00079 /** Destructor */ 00080 HomPoint::~HomPoint() 00081 { 00082 } 00083 00084 /** Obtain distance from the point to the origin. 00085 * @return distance to origin 00086 */ 00087 float 00088 HomPoint::distance() const 00089 { 00090 float d = sqrt( x() * x() + y() * y() + z() * z() ); 00091 return d; 00092 } 00093 00094 /** Move the point by the given coordiantes. 00095 * @param dx x-offset 00096 * @param dy y-offset 00097 * @param dz z-offset 00098 * @return reference to the moved point 00099 */ 00100 HomPoint& 00101 HomPoint::move(float dx, float dy, float dz) 00102 { 00103 this->x() += dx; 00104 this->y() += dy; 00105 this->z() += dz; 00106 00107 return *this; 00108 } 00109 00110 /** Move the point to the given coordiantes. 00111 * @param x new x-coordinate 00112 * @param y new y-coordinate 00113 * @param z new z-coordinate 00114 * @return reference to the moved point 00115 */ 00116 HomPoint& 00117 HomPoint::move_to(float x, float y, float z) 00118 { 00119 this->x() = x; 00120 this->y() = y; 00121 this->z() = z; 00122 00123 return *this; 00124 } 00125 00126 /** Compute the vector between two points. 00127 * @param p the other point 00128 * @return the vector between the two points 00129 */ 00130 HomVector 00131 HomPoint::operator-(const HomPoint& p) const 00132 { 00133 HomVector v; 00134 v.x( x() - p.x() ); 00135 v.y( y() - p.y() ); 00136 v.z( z() - p.z() ); 00137 00138 return v; 00139 } 00140 00141 } // end namespace fawkes