001/** 002 Returns a unit vector with the specified components (the vector will be normalized 003 automatically). The versions showing the array input actually take a variable length 004 argument list (vararg), so you can enter <code>newUnitVector(x, y, z, w)</code>, etc. 005 006 @method Vector newUnitVector(double... axesVararg) 007 @method Vector newUnitVector(GeomPoint origin, double... axesVararg) 008 @method Vector newUnitVector(Parameter... axesVararg) 009 @method Vector newUnitVector(GeomPoint origin, Parameter... axesVararg) 010 */ 011package geomss.app.GeomSSCommands.creators; 012 013import bsh.*; 014import geomss.geom.GeomPoint; 015import geomss.geom.Vector; 016import jahuwaldt.js.param.Parameter; 017 018public class newUnitVector { 019 020 public static String usage() { 021 return "usage: newUnitVector(x,y);, or newUnitVector(origin, x,y,z);"; 022 } 023 024 /** 025 * Implement newUnitVector(double... axesVararg) command. 026 */ 027 public static Vector invoke(Interpreter env, CallStack callstack, 028 double... axesVararg) { 029 return Vector.valueOf(axesVararg).toUnitVector(); 030 } 031 032 /** 033 * Implement newUnitVector(GeomPoint origin, double... axesVararg) command. 034 */ 035 public static Vector invoke(Interpreter env, CallStack callstack, 036 GeomPoint origin, double... axesVararg) { 037 Vector u = Vector.valueOf(axesVararg).toUnitVector(); 038 u.setOrigin(origin.immutable()); 039 return u; 040 } 041 042 /** 043 * Implement newUnitVector(Parameter... axesVararg) command. 044 */ 045 public static Vector invoke(Interpreter env, CallStack callstack, 046 Parameter... axesVararg) { 047 return Vector.valueOf(axesVararg).toUnitVector(); 048 } 049 050 /** 051 * Implement newUnitVector(GeomPoint origin, Parameter... axesVararg) command. 052 */ 053 public static Vector invoke(Interpreter env, CallStack callstack, 054 GeomPoint origin, Parameter... axesVararg) { 055 Vector u = Vector.valueOf(axesVararg).toUnitVector(); 056 u.setOrigin(origin.immutable()); 057 return u; 058 } 059 060}