var p0 = new r3Vect (2, 2, 2);
var p1 = new r3Vect (1, 1, 1);
var v = p0.sub (p1);
var distance = v.norm();
Of course, as a programming exercise, you can manually perform the "sub" and "norm" operations yourself, but for that, your code looks like it is missing some important things. Look up the definitions of vector subtraction and length computation and try again. :)
Concerning "abs", it does exist and it returns the absolute value of a scalar:
print (Math.abs (-10)); // Prints "10"
Don't confuse "abs" with "norm", even though these are written the same way in mathematical notation, and that "norm" works exactly like "abs" in the 1D case, the reverse is not true.
Regards,
Fredrik Bergholtz
Dear realsoft friends, during working for the ending of my colour script, I have built yesterday night a very interesting "distance" calculation and have some question to the professional script user :-)a) "abs" - does it exist in realsoft _javascript_ language? (absolute value)
b) I will print the distance measure between two spheres as a result in a popup window (I manage it ;-)
one little extract of my code lines :-) -------------------
function myVectorDistanceHook(obj, event, value)
{
var AV;
var V;
var AV2;
var abs = new r3Integer(); // absolute value
var distance = new r3Vect();
// var distance = 1;
var Pos = new r3Vect();
var Pos1 = new r3Vect();
var Pos2 = new r3Vect();
var x = new r3Vect();
var z = new r3Vect();
var y = new r3Vect();
var result;
v1 = new r3Vect(0.2, 0.1, 0.4);
v2 = new r3Vect(0.1, 0.15, 0.5);
// AV1 = Math.abs(x);
// AV2 = Math.abs(z);AV1 = Pos1.x - Pos2.x; // 346
AV2 = Pos1.z - Pos2.z;
A = Math.sqrt(AV1*AV1 + AV2*AV2);
V = Pos1.y - Pos2.y;
outObjA_distance = A; // outObjdistance ?
outObjV_distance = V;
}
------------------------ extract end
perhaps somebody can help me, would be great ! :-)))
have all a nice day, bye, regards, frank brübach, germany
![]()
XXL-Speicher, PC-Virenschutz, Spartarife & mehr: Nur im WEB.DE Club!
Jetzt gratis testen! http://freemail.web.de/home/landingpad/?mc=021130
