Lot of doc

This commit is contained in:
Thomas FORGIONE
2015-07-06 11:14:42 +02:00
parent c0eb2d26f5
commit f11b1ed7dc
15 changed files with 634 additions and 134 deletions
+121 -2
View File
@@ -1,10 +1,42 @@
/**
* @memberof L3D
* @namespace
* @description Contains eveything linked to hermite polynoms
*/
L3D.Hermite = {};
/**
* @memberof L3D.Hermite
* @constructor
* @description creates a hermite polynom
* @param t {Number[]|THREE.Vector3[]} time indices of the interpolation
* @param f {Number[]|THREE.Vector3[]} values of the polynom at each time
* @param fp {Number[]|THREE.Vector3[]} values of the derivative of the polynom at each time
*/
L3D.Hermite.Polynom = function(t, f, fp) {
/**
* @type {Number[]|THREE.Vector3[]}
* @description time indices of the interpolation
*/
this.times = t;
/**
* @type {Number[]|THREE.Vector3[]}
* @description values of the polynom at each time
*/
this.evals = f;
/**
* @type {Number[]|THREE.Vector3[]}
* @description values of the derivatives of the polynom at each time
*/
this.primes = fp;
/**
* @type {L3D.Hermite.BaseFunction[]}
* @description array of the base functions to evaluate the poylnom
*/
this.baseFunctions = [];
for (var i in this.times) {
@@ -12,6 +44,14 @@ L3D.Hermite.Polynom = function(t, f, fp) {
}
// Let's do something at least a little reusable
/**
* @type {Object}
* @description an object containing
* <ul>
* <li><code>whatType</code> : a string being <code>THREE.Vector3</code> or <code>number</code></li>
* <li><code>tools</code> : an object containg sum and mul, functions of the correct type</li>
* </ul>
*/
this.tools = {};
if (f[0] instanceof THREE.Vector3) {
this.tools.whatType = 'THREE.Vector3';
@@ -24,6 +64,11 @@ L3D.Hermite.Polynom = function(t, f, fp) {
}
};
/**
* Evaluates the polynom at a certain time
* @param t {Number} time at which you want to evaluate the polynom
* @return {Number|THREE.Vector3} the evaluation of the polynom at the given time
*/
L3D.Hermite.Polynom.prototype.eval = function(t) {
var ret;
@@ -67,6 +112,11 @@ L3D.Hermite.Polynom.prototype.eval = function(t) {
return ret;
};
/**
* Evaluates the derivate of the polynom at a certain time
* @param t {Number} time at which you want to evaluate the derivative of the polynom
* @return {Number|THREE.Vector3} the evaluation of the derivative of the polynom at the given time
*/
L3D.Hermite.Polynom.prototype.prime = function(t) {
var ret;
@@ -141,11 +191,32 @@ L3D.Hermite.Polynom.prototype.prime = function(t) {
return ret;
};
/**
* @memberof L3D.Hermite
* @constructor
* @description Represents a base function for evaluation of hermite polynoms
* @param index {Number} the index of the base function
* @param times {Number[]} the times for polynom interpolation
*/
L3D.Hermite.BaseFunction = function(index, times) {
/**
* @type {Number}
* @description the index of the base function
*/
this.index = index;
/**
* @type {Number[]}
* @description the times for polynom interpolation
*/
this.times = times;
};
/**
* Returns the evaluation of the base function
* @param t {Number} time at which you want to evaluate the base function
* @returns {Number} the evaluation of the base function at the given time
*/
L3D.Hermite.BaseFunction.prototype.eval = function(t) {
var ret = 1;
@@ -158,6 +229,11 @@ L3D.Hermite.BaseFunction.prototype.eval = function(t) {
return ret * ret;
};
/**
* Returns the evaluation of the derivative of the base function
* @param t {Number} time at which you want to evaluate the derivative of the base function
* @returns {Number} the evaluation of the derivative of the base function at the given time
*/
L3D.Hermite.BaseFunction.prototype.prime = function(t) {
var ret = 0;
@@ -170,16 +246,40 @@ L3D.Hermite.BaseFunction.prototype.prime = function(t) {
return this.eval(t) * ret;
};
/**
* @memberof L3D.Hermite
* @namespace
*/
L3D.Hermite.special = {};
// This polynom interpolates with two coords and one derivative
// t = [0,1]
/**
* @memberof L3D.Hermite.special
* @description Represents a simple hermite polynom where the times are [0, 1], and where
* the position is known at 0, 1 and where the derivative is only known at 1
* @constructor
* @param P0 {Number|THREE.Vector3} polynom at instant 0
* @param P1 {Number|THREE.Vector3} polynom at instant 1
* @param PP1 {Number|THREE.Vector3} derivative of the polynom at instant 1
*/
L3D.Hermite.special.Polynom = function(P0, P1, PP1) {
/**
* @type {Object}
* @description an object containing
* <ul>
* <li><code>whatType</code> : a string being <code>THREE.Vector3</code> or <code>number</code></li>
* <li><code>tools</code> : an object containg sum and mul, functions of the correct type</li>
* </ul>
*/
this.tools = {};
if (P0 instanceof THREE.Vector3) {
this.tools.sum = L3D.Tools.sum;
this.tools.mul = L3D.Tools.mul;
this.tools.diff = L3D.Tools.diff;
/**
* @type {Number|THREE.Vector3}
* @description b of ax²+bx+c
*/
this.c = P0.clone();
} else {
this.tools.sum = function(a,b) { return a+b; };
@@ -188,14 +288,33 @@ L3D.Hermite.special.Polynom = function(P0, P1, PP1) {
this.c = P0;
}
/**
* @type {Number}
* @description a of ax²+bx+c
*/
this.a = this.tools.sum(PP1, this.tools.diff(P0, P1));
/**
* @type {Number}
* @description b of ax²+bx+c
*/
this.b = this.tools.diff(this.tools.mul(this.tools.diff(P1,P0), 2), PP1);
};
/**
* Returns the evaluation of the polynom
* @param t {Number} time at which you want to evaluate the polynom
* @returns {Number|THREE.Vector3} the evaluation of the polynom at the given time
*/
L3D.Hermite.special.Polynom.prototype.eval = function(t) {
return this.tools.sum(this.tools.mul(this.a, t*t), this.tools.sum(this.tools.mul(this.b, t), this.c));
};
/**
* Returns the evaluation of the derivative of the polynom
* @param t {Number} time at which you want to evaluate the derivative of the polynom
* @returns {Number|THREE.Vector3} the evaluation of the derivative of the polynom at the given time
*/
L3D.Hermite.special.Polynom.prototype.prime = function(t) {
return this.tools.sum(this.tools.mul(this.a,2*t), this.b);
};
+54 -4
View File
@@ -1,17 +1,52 @@
/**
* @namespace
* @memberof L3D
* @description Contains various functions for manipulating THREE.Vector3
* Note that all these functions also work objects {x: x, y: y, z: z}, even if
* they're not THREE.Vector3
*/
L3D.Tools = {};
/**
* @memberof L3D.Tools
* @description Computes the sum of two vectors
* @param v1 {Vector} first vector of the sum
* @param v2 {Vector} second vector of the sum
* @returns {THREE.Vector3} v1 + v2
*/
L3D.Tools.sum = function(v1, v2) {
return new THREE.Vector3(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
};
/**
* @memberof L3D.Tools
* @description Computes the difference between two vectors
* @param v1 {Vector} first vector of the difference
* @param v2 {Vector} second vector of the difference
* @returns {THREE.Vector3} v1 - v2
*/
L3D.Tools.diff = function(v1, v2) {
return new THREE.Vector3(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
};
/**
* @memberof L3D.Tools
* @description Computes the dot product of two vectors
* @param v1 {Vector} first vector of the dot product
* @param v2 {Vector} second vector of the dot product
* @returns {THREE.Vector3} v1 * v2
*/
L3D.Tools.dot = function(v1, v2) {
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
};
/**
* @memberof L3D.Tools
* @description Computes the cross product of two vectors
* @param v1 {Vector} first vector of the cross product
* @param v2 {Vector} second vector of the cross product
* @returns {THREE.Vector3} v1 ^ v2
*/
L3D.Tools.cross = function(v1, v2) {
return new THREE.Vector3(
v1.y * v2.z - v1.z * v2.y,
@@ -20,18 +55,33 @@ L3D.Tools.cross = function(v1, v2) {
);
};
/**
* @memberof L3D.Tools
* @description Computes the product of a vector and a number
* @param v1 {Vector} vector of the product
* @param lambda {Number} number of the product
* @returns {THREE.Vector3} v1 * lambda
*/
L3D.Tools.mul = function(v1, lambda) {
return new THREE.Vector3(v1.x * lambda, v1.y * lambda, v1.z * lambda);
};
L3D.Tools.equals = function(v1, v2) {
return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z;
};
/**
* @memberof L3D.Tools
* @description Computes the square norm of a vector
* @param v {Vector} vector you want to compute the norm of
* @returns {Number} ||v||²
*/
L3D.Tools.norm2 = function(v) {
return v.x * v.x + v.y * v.y + v.z * v.z;
};
/**
* @memberof L3D.Tools
* @description Computes the norm of a vector
* @param v {Vector} vector you want to compute the norm of
* @returns {Number} ||v||
*/
L3D.Tools.norm = function(v) {
return Math.sqrt(L3D.Tools.norm2(v));
};