-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector.pd
More file actions
64 lines (44 loc) · 1.9 KB
/
Vector.pd
File metadata and controls
64 lines (44 loc) · 1.9 KB
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
//*******************************************************
//* File: C:/Users/User/Desktop/Third Year Project/CollisionAvoidanceSystem/Vector.pd
//* Author: Varuna
//* Created: 11:51:47 on Thursday January 8th 2015 UTC
//*******************************************************
class Vector ^=
abstract
var x : real;
var y : real;
var z : real;
var type : VectorType;
interface
function x;
function y;
function z;
function type;
function magnitude : real
^= ((x^2 + y^2 + z^2)^(0.5));
function getTwoDimensionalDistanceFrom(other : Vector) : real
pre type = VectorType Position & other.type = VectorType Position
^= ([x=other.x & y=other.y] : 0.0,
[] :(((x-other.x)^2) + ((y-other.y)^2)) ^ (0.5));
function getDistanceFrom(other : Vector) : real
pre type = VectorType Position & other.type = VectorType Position
^= (((x-other.x)^2) + ((y-other.y)^2) + ((z-other.z)^2)) ^ (0.5);
function positionAtTime(t : real, velocity : Vector) : Vector
pre type = VectorType Position & velocity.type = VectorType Velocity
^= Vector { x + (velocity.x*t), y + (velocity.y*t), z + (velocity.z*t), VectorType Position};
function dotProduct(other : Vector) : real
^= ((x * other.x) + (y * other.y) + (z * other.z));
function plus(other : Vector, resultType : VectorType) : Vector
^= Vector { x + other.x, y + other.y, z + other.z, resultType};
redefine function toString : string
^= "(" ++ x.rounddn.toString ++ ")x + (" ++ y.rounddn.toString ++ ")y + (" ++ z.rounddn.toString ++ ")z";
operator -(other : Vector) : Vector
pre type = other.type
^= Vector { x - other.x, y - other.y, z - other.z, type}
assert other = self ==> result.magnitude = 0.0;
operator *(scalar : real) : Vector
^= Vector { x * scalar, y * scalar, z * scalar, type};
build{!x : real, !y : real, !type : VectorType}
post z != 0.0;
build{!x : real, !y : real, !z : real, !type : VectorType};
end;