source: trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrVector2f.h @ 1699

Last change on this file since 1699 was 1699, checked in by vrinside, 14 years ago
File size: 1.5 KB
Line 
1#pragma once
2#include <vrmath/vrLinmath.h>
3
4#include <cstdlib>
5#include <cmath>
6
7//#define LmExport
8class LmExport vrVector2f {
9public :
10        float   x, y;
11
12public :
13        vrVector2f() : x(0.0f), y(0.0f) {}
14        vrVector2f(const vrVector2f& v) : x(v.x), y(v.y) {}
15        vrVector2f(float x1, float y1) : x(x1), y(y1) {}
16
17        void set(float x1, float y1);
18        void set(const vrVector2f& v);
19
20        float dot() const;
21        float length() const;
22        float distance(const vrVector2f& v) const;
23        float distance(float x1, float y1) const;
24        float distanceSquare(const vrVector2f& v) const;
25        float distanceSquare(float x1, float y1) const;
26};
27
28inline void vrVector2f::set(float x1, float y1)
29{
30        x = x1;
31        y = y1;
32}
33
34inline void vrVector2f::set(const vrVector2f& v)
35{
36        x = v.x;
37        y = v.y;
38}
39
40inline float vrVector2f::dot() const
41{
42        return (x * x + y * y);
43}
44
45
46inline float vrVector2f::length() const
47{
48        return sqrt(x * x + y * y);
49}
50
51
52
53inline float vrVector2f::distance(const vrVector2f& v) const
54{
55        float x1 = (v.x - x) , y1 = (v.y - y);
56        return sqrt(x1 * x1 + y1 * y1);
57}
58
59
60
61inline float vrVector2f::distance(float x1, float y1) const
62{       
63        float x2 = (x1 - x) , y2 = (y1 - y);
64        return sqrt(x2 * x2 + y2 * y2);
65}
66
67
68
69
70inline float vrVector2f::distanceSquare(const vrVector2f& v) const
71{       
72        float x1 = (v.x - x) , y1 = (v.y - y);
73        return (x1 * x1 + y1 * y1);
74}
75
76inline float vrVector2f::distanceSquare(float x1, float y1) const
77{       
78        float x2 = (x1 - x) , y2 = (y1 - y);
79        return (x2 * x2 + y2 * y2);
80}
Note: See TracBrowser for help on using the repository browser.