Ignore:
Timestamp:
Apr 30, 2010, 9:03:57 AM (16 years ago)
Author:
Tillmann Crueger <crueger@…>
Children:
7a8319
Parents:
c53e0b
git-author:
Tillmann Crueger <crueger@…> (04/30/10 08:26:28)
git-committer:
Tillmann Crueger <crueger@…> (04/30/10 09:03:57)
Message:

Added a class Space to represent general subspaces of R3 (planes and lines)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/Plane.cpp

    rc53e0b r0e9394  
    88#include "Plane.hpp"
    99#include "vector.hpp"
     10#include "defs.hpp"
    1011#include "Exceptions/LinearDependenceException.hpp"
    1112#include "info.hpp"
     
    1314#include "verbose.hpp"
    1415#include "Helpers/Assert.hpp"
     16#include <cmath>
    1517
    1618/**
     
    163165  return res;
    164166};
     167
     168/************ Methods inherited from Space ****************/
     169
     170double Plane::distance(Vector &point){
     171  double res = point.ScalarProduct(*normalVector)-offset;
     172  return fabs(res);
     173}
     174
     175Vector Plane::getClosestPoint(Vector &point){
     176  Vector difference = distance(point) * (*normalVector);
     177  if(difference.IsZero()){
     178    // the point itself lies on the plane
     179    return point;
     180  }
     181  // get the direction this vector is pointing
     182  double sign = difference.ScalarProduct(*normalVector);
     183  // sign cannot be zero, since normalVector and difference are both != zero
     184  sign = sign/fabs(sign);
     185  return (point - (sign * difference));
     186}
     187
     188bool Plane::isContained(Vector &point){
     189  return (point.ScalarProduct(*normalVector) - offset) < MYEPSILON;
     190}
Note: See TracChangeset for help on using the changeset viewer.