Commit 40efd05d authored by 16김민성's avatar 16김민성

Modify vector class; no use prototype

parent 36d0422c
......@@ -15,84 +15,81 @@ class Vector {
this.y = y || 0;
this.z = z || 0;
}
}
Vector.prototype = {
negative: function() {
negative() {
return new Vector(-this.x, -this.y, -this.z);
},
add: function(v) {
}
add(v) {
if (v instanceof Vector) return new Vector(this.x + v.x, this.y + v.y, this.z + v.z);
else return new Vector(this.x + v, this.y + v, this.z + v);
},
subtract: function(v) {
}
subtract(v) {
if (v instanceof Vector) return new Vector(this.x - v.x, this.y - v.y, this.z - v.z);
else return new Vector(this.x - v, this.y - v, this.z - v);
},
multiply: function(v) {
}
multiply (v) {
if (v instanceof Vector) return new Vector(this.x * v.x, this.y * v.y, this.z * v.z);
else return new Vector(this.x * v, this.y * v, this.z * v);
},
divide: function(v) {
}
divide (v) {
if (v instanceof Vector) return new Vector(this.x / v.x, this.y / v.y, this.z / v.z);
else return new Vector(this.x / v, this.y / v, this.z / v);
},
equals: function(v) {
}
equals (v) {
return this.x == v.x && this.y == v.y && this.z == v.z;
},
dot: function(v) {
}
dot (v) {
return this.x * v.x + this.y * v.y + this.z * v.z;
},
cross: function(v) {
}
cross (v) {
return new Vector(
this.y * v.z - this.z * v.y,
this.z * v.x - this.x * v.z,
this.x * v.y - this.y * v.x
);
},
length: function() {
}
length () {
return Math.sqrt(this.dot(this));
},
unit: function() {
}
unit () {
return this.divide(this.length());
},
min: function() {
}
min () {
return Math.min(Math.min(this.x, this.y), this.z);
},
max: function() {
}
max () {
return Math.max(Math.max(this.x, this.y), this.z);
},
toAngles: function() {
}
toAngles () {
return {
theta: Math.atan2(this.z, this.x),
phi: Math.asin(this.y / this.length())
};
},
angleTo: function(a) {
}
angleTo (a) {
return Math.acos(this.dot(a) / (this.length() * a.length()));
},
toArray: function(n) {
}
toArray (n) {
return [this.x, this.y, this.z].slice(0, n || 3);
},
clone: function() {
}
clone () {
return new Vector(this.x, this.y, this.z);
},
init: function(x, y, z) {
}
init (x, y, z) {
this.x = x; this.y = y; this.z = z;
return this;
}
};
}
class UserInfo {
constructor() {
this.pos = new Vector(80, 0, 0);
this.distHand = 80;
this.dist = 80;
}
}
class DroneInfo {
constructor() {
this.distDrone = 500;
this.dist = 500;
this.pos = new Vector(500, 0, 0); // Current position of the drone. It is changed only if a real position of dron is changed.
this.pitch = 0;
this.roll = 0;
......@@ -100,19 +97,10 @@ class DroneInfo {
}
}
class DroneDest {
constructor() {
this.distDrone = 500;
this.pos = new Vector(500, 0, 0);
}
}
var origin = new Vector(0, 0, 0);
function handToDroneDelta(_nextHand) {
var delta = _nextHand - origin;
delta = delta.multiply()
return posDrone.add(delta);
}
function
\ No newline at end of file
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment