/* Return unit magnitude vector in direction of v */ HVect V3_Unit(HVect v) { static HVect u = {0, 0, 0, 0}; float vlen = sqrt(V3_Norm(v)); if (vlen != 0.0) { u.x = v.x/vlen; u.y = v.y/vlen; u.z = v.z/vlen; } return (u); }
static HVect V3_Unit (HVect v) { static HVect u = {0, 0, 0, 0}; double vlen = sqrt(V3_Norm(v)); if (vlen != 0.0) u.x = v.x/vlen; u.y = v.y/vlen; u.z = v.z/vlen; return (u); }
/* Halve arc between unit vectors v0 and v1. */ HVect V3_Bisect(HVect v0, HVect v1) { HVect v = {0, 0, 0, 0}; float Nv; v = V3_Add(v0, v1); Nv = V3_Norm(v); if (Nv < 1.0e-5) { v = V3_(0, 0, 1); } else { v = V3_Scale(v, 1/sqrt(Nv)); } return (v); }
static HVect ConstrainToAxis (HVect loose, HVect axis) { HVect onPlane; register double norm; onPlane = V3_Sub(loose, V3_Scale(axis, V3_Dot(axis, loose))); norm = V3_Norm(onPlane); if (norm > 0.0) { if (onPlane.z < 0.0) onPlane = V3_Negate(onPlane); return ( V3_Scale(onPlane, 1/sqrt(norm)) ); } /* else drop through */ /* ================= */ if (axis.z == 1) onPlane = V3_(1.0, 0.0, 0.0); else onPlane = V3_Unit(V3_(-axis.y, axis.x, 0.0)); return (onPlane); }