-
Notifications
You must be signed in to change notification settings - Fork 0
/
coordinate3d.cpp
69 lines (51 loc) · 2.08 KB
/
coordinate3d.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/***************************************************************************
coordinate3d.cpp - description
-------------------
begin : Wed Sep 3 2003
copyright : (C) 2000-2003 by Anthony Liekens
email : anthony@liekens.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "coordinate3d.h"
Coordinate3D::Coordinate3D() {
}
Coordinate3D::Coordinate3D(double x, double y, double z) {
this->x = x;
this->y = y;
this->z = z;
}
Coordinate3D::~Coordinate3D(){
}
void
Coordinate3D::write(std::ostream &stream) const {
stream << (int)( 1000 * x / ( z + 500 ) ) << " " << (int)( 1000 * y / ( z + 500 ) );
}
Coordinate*
Coordinate3D::projection( double xOffset, double yOffset, double scale, double distance ) {
// determine 2 dimensional x, y coordinates
double x2D = ( x * scale ) / ( z + distance ) + xOffset;
double y2D = ( y * scale ) / ( z + distance ) + yOffset;
return new Coordinate( (int)x2D, (int)y2D );
}
void
Coordinate3D::applyMatrix( Matrix< double >* m ) {
double x3D = (*m)[ 0 ][ 0 ] * x + (*m)[ 0 ][ 1 ] * y + (*m)[ 0 ][ 2 ] * z;
double y3D = (*m)[ 1 ][ 0 ] * x + (*m)[ 1 ][ 1 ] * y + (*m)[ 1 ][ 2 ] * z;
double z3D = (*m)[ 2 ][ 0 ] * x + (*m)[ 2 ][ 1 ] * y + (*m)[ 2 ][ 2 ] * z;
x = x3D;
y = y3D;
z = z3D;
}
void
Coordinate3D::translate( Coordinate3D* c ) {
x += c->getX();
y += c->getY();
z += c->getZ();
}