1 if(!dojo._hasResource["dojox.gfx3d.vector"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.gfx3d.vector"] = true;
3 dojo.provide("dojox.gfx3d.vector");
5 dojo.mixin(dojox.gfx3d.vector, {
7 // summary: sum of the vectors
8 var v = {x: 0, y: 0, z:0};
9 dojo.forEach(arguments, function(item){ v.x += item.x; v.y += item.y; v.z += item.z; });
14 // summary: center of the vectors
15 var l = arguments.length;
17 return {x: 0, y: 0, z: 0};
19 var v = dojox.gfx3d.vector.sum(arguments);
20 return {x: v.x/l, y: v.y/l, z: v.z/l};
23 substract: function(/* Pointer */a, /* Pointer */b){
24 return {x: a.x - b.x, y: a.y - b.y, z: a.z - b.z};
27 _crossProduct: function(x, y, z, u, v, w){
28 // summary: applies a cross product of two vectorss, (x, y, z) and (u, v, w)
29 // x: Number: an x coordinate of a point
30 // y: Number: a y coordinate of a point
31 // z: Number: a z coordinate of a point
32 // u: Number: an x coordinate of a point
33 // v: Number: a y coordinate of a point
34 // w: Number: a z coordinate of a point
35 return {x: y * w - z * v, y: z * u - x * w, z: x * v - y * u}; // Object
38 crossProduct: function(/* Number||Point */ a, /* Number||Point */ b, /* Number, optional */ c, /* Number, optional */ d, /* Number, optional */ e, /* Number, optional */ f){
39 // summary: applies a matrix to a point
40 // matrix: dojox.gfx3d.matrix.Matrix3D: a 3D matrix object to be applied
41 // a: Number: an x coordinate of a point
42 // b: Number: a y coordinate of a point
43 // c: Number: a z coordinate of a point
44 // d: Number: an x coordinate of a point
45 // e: Number: a y coordinate of a point
46 // f: Number: a z coordinate of a point
47 if(arguments.length == 6 && dojo.every(arguments, function(item){ return typeof item == "number"; })){
48 return dojox.gfx3d.vector._crossProduct(a, b, c, d, e, f); // Object
57 return dojox.gfx3d.vector._crossProduct(a.x, a.y, a.z, b.x, b.y, b.z); // Object
60 _dotProduct: function(x, y, z, u, v, w){
61 // summary: applies a cross product of two vectorss, (x, y, z) and (u, v, w)
62 // x: Number: an x coordinate of a point
63 // y: Number: a y coordinate of a point
64 // z: Number: a z coordinate of a point
65 // u: Number: an x coordinate of a point
66 // v: Number: a y coordinate of a point
67 // w: Number: a z coordinate of a point
68 return x * u + y * v + z * w; // Number
70 dotProduct: function(/* Number||Point */ a, /* Number||Point */ b, /* Number, optional */ c, /* Number, optional */ d, /* Number, optional */ e, /* Number, optional */ f){
71 // summary: applies a matrix to a point
72 // matrix: dojox.gfx3d.matrix.Matrix3D: a 3D matrix object to be applied
73 // a: Number: an x coordinate of a point
74 // b: Number: a y coordinate of a point
75 // c: Number: a z coordinate of a point
76 // d: Number: an x coordinate of a point
77 // e: Number: a y coordinate of a point
78 // f: Number: a z coordinate of a point
79 if(arguments.length == 6 && dojo.every(arguments, function(item){ return typeof item == "number"; })){
80 return dojox.gfx3d.vector._dotProduct(a, b, c, d, e, f); // Object
89 return dojox.gfx3d.vector._dotProduct(a.x, a.y, a.z, b.x, b.y, b.z); // Object
92 normalize: function(/* Point||Array*/ a, /* Point */ b, /* Point */ c){
93 // summary: find the normal of the implicit surface
98 if(a instanceof Array){
99 l = a[0]; m = a[1]; n = a[2];
104 var u = dojox.gfx3d.vector.substract(m, l);
105 var v = dojox.gfx3d.vector.substract(n, l);
106 return dojox.gfx3d.vector.crossProduct(u, v);