00001 // This is core/vcsl/vcsl_cylindrical_to_cartesian_3d.cxx 00002 #include "vcsl_cylindrical_to_cartesian_3d.h" 00003 #include <vcl_cassert.h> 00004 #include <vcl_cmath.h> // for sqrt(), cos(), sin() 00005 00006 //--------------------------------------------------------------------------- 00007 // Is `this' invertible at time `time'? 00008 // REQUIRE: valid_time(time) 00009 //--------------------------------------------------------------------------- 00010 bool vcsl_cylindrical_to_cartesian_3d::is_invertible(double time) const 00011 { 00012 // require 00013 assert(valid_time(time)); 00014 00015 return true; 00016 } 00017 00018 //--------------------------------------------------------------------------- 00019 // Image of `v' by `this' 00020 // REQUIRE: is_valid() 00021 // REQUIRE: v.size()==3 00022 //--------------------------------------------------------------------------- 00023 vnl_vector<double> 00024 vcsl_cylindrical_to_cartesian_3d::execute(const vnl_vector<double> &v, 00025 double /*time*/) const 00026 { 00027 // require 00028 assert(is_valid()); 00029 assert(v.size()==3); 00030 00031 vnl_vector<double> result(3); 00032 00033 double rho=v.get(0); 00034 double theta=v.get(1); 00035 double z=v.get(2); 00036 00037 double x=rho*vcl_cos(theta); 00038 double y=rho*vcl_sin(theta); 00039 00040 result.put(0,x); 00041 result.put(1,y); 00042 result.put(2,z); 00043 00044 return result; 00045 } 00046 00047 //--------------------------------------------------------------------------- 00048 // Image of `v' by the inverse of `this' 00049 // REQUIRE: is_valid() 00050 // REQUIRE: is_invertible(time) 00051 // REQUIRE: v.size()==3 00052 //--------------------------------------------------------------------------- 00053 vnl_vector<double> 00054 vcsl_cylindrical_to_cartesian_3d::inverse(const vnl_vector<double> &v, 00055 double time) const 00056 { 00057 // require 00058 assert(is_valid()); 00059 assert(is_invertible(time)); 00060 assert(v.size()==3); 00061 00062 vnl_vector<double> result(3); 00063 00064 double x=v.get(0); 00065 double y=v.get(1); 00066 double z=v.get(2); 00067 00068 double rho=vcl_sqrt(x*x+y*y); 00069 double theta=vcl_atan2(y,x); 00070 00071 result.put(0,rho); 00072 result.put(1,theta); 00073 result.put(2,z); 00074 00075 return result; 00076 } 00077 00078 // Return the reference to the unique vcsl_length object 00079 vcsl_cylindrical_to_cartesian_3d_sptr 00080 vcsl_cylindrical_to_cartesian_3d::instance() 00081 { 00082 static vcsl_cylindrical_to_cartesian_3d_sptr instance_ 00083 = new vcsl_cylindrical_to_cartesian_3d; 00084 return instance_; 00085 }