Changeset 59e7832 for molecuilder/src/Plane.cpp
- Timestamp:
- Apr 30, 2010, 1:33:12 PM (16 years ago)
- Children:
- 25e17e9
- Parents:
- 4eee8f
- File:
-
- 1 edited
-
molecuilder/src/Plane.cpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/Plane.cpp
r4eee8f r59e7832 44 44 * If no offset is given a plane through origin is assumed 45 45 */ 46 Plane::Plane(const Vector &y1, const Vector &y2, double _offset) throw( LinearDependenceException) :46 Plane::Plane(const Vector &y1, const Vector &y2, double _offset) throw(ZeroVectorException,LinearDependenceException) : 47 47 normalVector(new Vector()), 48 48 offset(_offset) … … 50 50 Vector x1 = y1; 51 51 Vector x2 = y2; 52 if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON) || (fabs(x1.Angle(x2)) < MYEPSILON)) { 52 if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON)) { 53 throw ZeroVectorException(__FILE__,__LINE__); 54 } 55 56 if((fabs(x1.Angle(x2)) < MYEPSILON)) { 53 57 throw LinearDependenceException(__FILE__,__LINE__); 54 58 } … … 92 96 93 97 94 Vector Plane::getNormal() {98 Vector Plane::getNormal() const{ 95 99 return *normalVector; 96 100 } 97 101 98 double Plane::getOffset() {102 double Plane::getOffset() const{ 99 103 return offset; 100 104 } … … 106 110 vector<Vector> Plane::getPointsOnPlane(){ 107 111 std::vector<Vector> res; 112 res.reserve(3); 108 113 // first point on the plane 109 res[0] = getOffsetVector(); 110 // first is orthogonal to the plane... 111 // an orthogonal vector to this one lies on the plane 114 res.push_back(getOffsetVector()); 115 // get a vector that has direction of plane 112 116 Vector direction; 113 direction.GetOneNormalVector( res[0]);114 res [1] = res[0]+direction;115 // get an orthogonal vector to direction and offset (lies on theplane)116 direction.VectorProduct( res[0]);117 direction.GetOneNormalVector(getNormal()); 118 res.push_back(res[0]+direction); 119 // get an orthogonal vector to direction and normal (has direction of plane) 120 direction.VectorProduct(getNormal()); 117 121 direction.Normalize(); 118 res [2] = res[0] +direction;122 res.push_back(res[0] +direction); 119 123 return res; 120 124 } … … 178 182 179 183 Vector Plane::getClosestPoint(const Vector &point) const{ 180 Vector difference = distance(point) * (*normalVector);181 if( difference.IsZero()){184 double factor = point.ScalarProduct(*normalVector)-offset; 185 if(fabs(factor) < MYEPSILON){ 182 186 // the point itself lies on the plane 183 187 return point; 184 188 } 185 // get the direction this vector is pointing 186 double sign = difference.ScalarProduct(*normalVector); 187 // sign cannot be zero, since normalVector and difference are both != zero 188 sign = sign/fabs(sign); 189 return (point - (sign * difference)); 189 Vector difference = factor * (*normalVector); 190 return (point - difference); 190 191 } 192 193 // Operators 194 195 ostream &operator << (ostream &ost,const Plane &p){ 196 ost << "<" << p.getNormal() << ";x> - " << p.getOffset() << "=0"; 197 return ost; 198 }
Note:
See TracChangeset
for help on using the changeset viewer.
