source: molecuilder/src/Line.cpp@ 495a53

Last change on this file since 495a53 was 25e17e9, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Added a line class that represents one dimensional subspaces

  • Property mode set to 100644
File size: 632 bytes
Line 
1/*
2 * Line.cpp
3 *
4 * Created on: Apr 30, 2010
5 * Author: crueger
6 */
7
8#include "Line.hpp"
9
10#include <cmath>
11
12#include "vector.hpp"
13
14Line::Line(Vector &_origin, Vector &_direction) :
15 origin(new Vector(_origin)),
16 direction(new Vector(_direction))
17{
18 direction->Normalize();
19}
20
21Line::~Line()
22{}
23
24
25double Line::distance(const Vector &point) const{
26 return fabs(point.ScalarProduct(*direction) - origin->ScalarProduct(*direction));
27}
28
29Vector Line::getClosestPoint(const Vector &point) const{
30 double factor = point.ScalarProduct(*direction) - origin->ScalarProduct(*direction);
31 return (point - (factor * (*direction)));
32}
Note: See TracBrowser for help on using the repository browser.