source: git/src/vector3.cc @ 56da40e

RELEASE/1.1RELEASE/1.2debug-cidebug-ci-sanitisersfaster-cavernloglog-selectstereostereo-2025walls-datawalls-data-hanging-as-warningwarn-only-for-hanging-survey
Last change on this file since 56da40e was 5809313, checked in by Olly Betts <olly@…>, 24 years ago

Mark's new wxwindows version of aven

git-svn-id: file:///home/survex-svn/survex/trunk@624 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100644
File size: 2.3 KB
Line 
1//
2//  vector3.cxx
3//
4//  C++ class for 3-element vectors
5//
6//  Copyright (C) 2000-2001, Mark R. Shinwell.
7//
8//  This program is free software; you can redistribute it and/or modify
9//  it under the terms of the GNU General Public License as published by
10//  the Free Software Foundation; either version 2 of the License, or
11//  (at your option) any later version.
12//
13//  This program is distributed in the hope that it will be useful,
14//  but WITHOUT ANY WARRANTY; without even the implied warranty of
15//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16//  GNU General Public License for more details.
17//
18//  You should have received a copy of the GNU General Public License
19//  along with this program; if not, write to the Free Software
20//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21//
22
23#include "vector3.h"
24
25#include <math.h>
26
27Vector3::Vector3() : x(0.0), y(0.0), z(0.0)
28{
29}
30
31Vector3::Vector3(double a, double b, double c)
32{
33    x = a;
34    y = b;
35    z = c;
36}
37
38Vector3::~Vector3()
39{
40}
41
42double Vector3::magnitude()
43{
44    return sqrt(x*x + y*y + z*z);
45}
46
47void Vector3::normalise()
48{
49    double mag = magnitude();
50    x /= mag;
51    y /= mag;
52    z /= mag;
53}
54
55double dot(const Vector3& left, const Vector3& right)
56{
57    return left.x*right.x + left.y*right.y + left.z*right.z;
58}
59
60Vector3& Vector3::operator=(const Vector3& r)
61{
62    x = r.x;
63    y = r.y;
64    z = r.z;
65
66    return *this;
67}
68
69void Vector3::set(double nx, double ny, double nz)
70{
71    x = nx;
72    y = ny;
73    z = nz;
74}
75
76Vector3& Vector3::operator*=(const double f)
77{
78    x *= f;
79    y *= f;
80    z *= f;
81
82    return *this;
83}
84
85Vector3& Vector3::operator/=(const double f)
86{
87    x /= f;
88    y /= f;
89    z /= f;
90
91    return *this;
92}
93
94Vector3 operator*(const Vector3& v, const double f)
95{
96    Vector3 o;
97    o.x = v.x * f;
98    o.y = v.y * f;
99    o.z = v.z * f;
100
101    return o;
102}
103
104Vector3 operator*(const double f, const Vector3& v)
105{
106    Vector3 o;
107    o.x = v.x * f;
108    o.y = v.y * f;
109    o.z = v.z * f;
110
111    return o;
112}
113
114Vector3 operator*(const Vector3& v1, const Vector3& v2)
115{
116    // Cross product.
117
118    Vector3 o;
119    o.x = v1.y*v2.z - v1.z*v2.y;
120    o.y = v1.z*v2.x - v1.x*v2.z;
121    o.z = v1.x*v2.y - v1.y*v2.x;
122
123    return o;
124}
125
126Vector3 operator+(const Vector3& v1, const Vector3& v2)
127{
128    Vector3 o;
129    o.x = v1.x + v2.x;
130    o.y = v1.y + v2.y;
131    o.z = v1.z + v2.z;
132
133    return o;
134}
Note: See TracBrowser for help on using the repository browser.