source: git/src/vector3.cc @ 4f853b2

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 4f853b2 was cbfa50d, checked in by Olly Betts <olly@…>, 22 years ago

Sorted out config.h inclusion, GL header inclusion, and removed some
needless inclusion of wx headers.

git-svn-id: file:///home/survex-svn/survex/branches/survex-1_1@2342 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

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