// ------------------------------ // vec3test.cpp vectors 2 // ------------------------------ #include "w.h" #include "vec3.h" // ----------------------------------------------------------- vec e1(1,0,0); vec e2(0,1,0); vec e3(0,0,1); // ---------------------------------------------------------- void main() { nl(0); banner("vec3test.cpp"); vec u(1,2,3), v(-2,1,5),w; p("u = "); pl(u); p("v = "); pl(v); w = vsum(u,v); p("w = vsum(u,v) = "); pl(w); p("w = u + v = "); pl(u+v); w = u = vec(2,-1,5); p("w = u = vec(2,-1,5) = "); pl(w); vec z = vcross(u,w); p("z = u x w = "); pl(z); w = vec(-1,2,0); p("w = (-1,2,0) = "); pl(w); p("(u x v).w = "); pl(v3dot(u,v,w)); p("e1 x e2 = "); pl(vcross(e1,e2)); vec vc = v(cos); p("cos(v) = "); pl(vc); p("v[2] = "); pl(v[2]); v = 1/3.0; p("v = 1/3.0 => -v = "); pl(-v); p("u = "); p(u); p(" v = "); pl(v); p("u - v = "); pl(u+v); p("u*v = "); pl(u*v); p("sin(1,2,3) = "); pl(vec(sin,1,2,3)); u = vec(4,3,2); p("u = "); pl(u); p("cos(u) = "); pl(u(cos)); } // ---------------------------------------------------------- /* output -------------- vec3test.cpp -------------- u = (1,2,3) v = (-2,1,5) w = vsum(u,v) = (-1,3,8) w = u + v = (-1,3,8) w = u = vec(2,-1,5) = (2,-1,5) z = u x w = (0,0,0) w = (-1,2,0) = (-1,2,0) (u x v).w = -30 e1 x e2 = (0,0,1) cos(v) = (-0.416147,0.540302,0.283662) v[2] = 1 v = 1/3.0 => -v = (-0.333333,-0.333333,-0.333333) u = (2,-1,5) v = (0.333333,0.333333,0.333333) u - v = (2.33333,-0.666667,5.33333) u*v = (0.666667,-0.333333,1.66667) sin(1,2,3) = (0.841471,0.909297,0.14112) u = (4,3,2) cos(u) = (-0.653644,-0.989992,-0.416147) */