Created
September 16, 2012 12:41
Revisions
-
netguy204 created this gist
Sep 16, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ deffun vector(x, y, z) { x: x, y: y, z: z } in deffun sub(v1, v2) vector( -(v1.x, v2.x), -(v1.y, v2.y), -(v1.z, v2.z)) in deffun abs(x) if <(x, 0) then -(0, x) else x in deffun mult(x, y) defvar yi = 0 in defvar r = 0 in { for(yi = 0; <(yi, abs(y)); yi++) { r = +(r, x); }; abs(r); } in deffun dotP(v1, v2) +(mult(v1.x, v2.x), mult(v1.y, v2.y), mult(v1.z, v2.z)); in deffun dist2(v1, v2) defvar td = sub(v1, v2) in { dotP(td, td) } in { print(dotP(vector(1,2,3), vector(4,5,6))); print(" "); print(dist2(vector(1,2,3), vector(4,5,6))); ""; }