Fawkes API
Fawkes Development Version
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
hom_point.cpp
1
2
/***************************************************************************
3
* hom_point.cpp - Homogenous point
4
*
5
* Created: Thu Sep 27 17:01:55 2007
6
* Copyright 2007-2008 Daniel Beck
7
*
8
****************************************************************************/
9
10
/* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version. A runtime exception applies to
14
* this software (see LICENSE.GPL_WRE file mentioned below for details).
15
*
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU Library General Public License for more details.
20
*
21
* Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22
*/
23
24
#include "hom_point.h"
25
#include "hom_vector.h"
26
#include <cmath>
27
#include <cstdio>
28
#include <exception>
29
30
namespace
fawkes {
31
32
/** @class HomPoint geometry/hom_point.h
33
* A homogeneous point.
34
* @author Daniel Beck
35
*/
36
37
/**Constructor.
38
* @param x the x-coordinate
39
* @param y the y-coordinate
40
* @param z the z-coordinate
41
*/
42
HomPoint::HomPoint
(
float
x,
float
y,
float
z)
43
:
HomCoord
(x, y, z, 1.0)
44
{
45
}
46
47
/** Constructor.
48
* Constructs a 2-dimensional vector from a cart_coord_2d_t struct.
49
*@param coord a structure for a 2-dimensional coordinate
50
*/
51
HomPoint::HomPoint
(
cart_coord_2d_t
coord)
52
:
HomCoord
(coord.x, coord.y, 0.0, 1.0)
53
{
54
}
55
56
/** Constructor.
57
* Constructs a 3-dimensional vector from a cart_coord_3d_t struct.
58
*@param coord a structure for a 3-dimensional coordinate
59
*/
60
HomPoint::HomPoint
(
cart_coord_3d_t
coord)
61
:
HomCoord
(coord.x, coord.y, coord.z, 1.0)
62
{
63
}
64
65
/** Constructor.
66
* @param h a HomCoord
67
*/
68
HomPoint::HomPoint
(
const
HomCoord
& h)
69
:
HomCoord
(h)
70
{
71
if
( 1.0 !=
w
() )
72
{
73
printf(
"HomPoint(const HomCoord& h): The forth component of a "
74
"homogeneous point has to be 1.0 but is %f\n"
,
w
());
75
throw
std::exception();
76
}
77
}
78
79
/** Destructor */
80
HomPoint::~HomPoint
()
81
{
82
}
83
84
/** Obtain distance from the point to the origin.
85
* @return distance to origin
86
*/
87
float
88
HomPoint::distance
()
const
89
{
90
float
d = sqrt(
x
() *
x
() +
y
() *
y
() +
z
() *
z
() );
91
return
d;
92
}
93
94
/** Move the point by the given coordiantes.
95
* @param dx x-offset
96
* @param dy y-offset
97
* @param dz z-offset
98
* @return reference to the moved point
99
*/
100
HomPoint
&
101
HomPoint::move
(
float
dx,
float
dy,
float
dz)
102
{
103
this->
x
() += dx;
104
this->
y
() += dy;
105
this->
z
() += dz;
106
107
return
*
this
;
108
}
109
110
/** Move the point to the given coordiantes.
111
* @param x new x-coordinate
112
* @param y new y-coordinate
113
* @param z new z-coordinate
114
* @return reference to the moved point
115
*/
116
HomPoint
&
117
HomPoint::move_to
(
float
x,
float
y,
float
z)
118
{
119
this->
x
() =
x
;
120
this->
y
() =
y
;
121
this->
z
() =
z
;
122
123
return
*
this
;
124
}
125
126
/** Compute the vector between two points.
127
* @param p the other point
128
* @return the vector between the two points
129
*/
130
HomVector
131
HomPoint::operator-
(
const
HomPoint
& p)
const
132
{
133
HomVector
v;
134
v.
x
(
x
() - p.
x
() );
135
v.
y
(
y
() - p.
y
() );
136
v.
z
(
z
() - p.
z
() );
137
138
return
v;
139
}
140
141
}
// end namespace fawkes
src
libs
geometry
hom_point.cpp
Generated by
1.8.1.1