00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "stdafx.h"
00021
00022 #include <iostream>
00023
00024 #include "gul_types.h"
00025 #include "gul_vector.h"
00026 #include "gul_matrix.h"
00027 #include "guma_lineq.h"
00028
00029 namespace guma {
00030
00031 using gul::Ptr;
00032 using gul::rtr;
00033 using gul::point;
00034 using gul::normalize;
00035 using gul::MMProduct;
00036 using gul::cross_product;
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 template< class U >
00049 void CommonCoordinateSystem(
00050 const point<U>& B, const point<U>& P, const point<U>& Ab,
00051 const point<U>& Pb, Ptr< Ptr<U> >& T )
00052 {
00053 point<U> a1,a2,a3,b1,b2,b3;
00054 Ptr< Ptr<U> > Ta,Tb;
00055 int i;
00056
00057 Ta.reserve_pool(3);
00058 Tb.reserve_pool(3);
00059 for( i = 0; i < 3; i++ )
00060 {
00061 Ta[i].reserve_pool(3);
00062 Tb[i].reserve_pool(3);
00063 }
00064
00065 normalize( &a1, B );
00066 normalize( &a2, P-((P*a1)*a1) );
00067 normalize( &a3, cross_product(a1,a2) );
00068
00069 normalize( &b1, -Ab );
00070 normalize( &b2, P-((P*b1)*b1) );
00071 normalize( &b3, cross_product(b1,b2) );
00072
00073 Tb[0][0] = b1[0]; Tb[0][1] = b1[1]; Tb[0][2] = b1[2];
00074 Tb[1][0] = b2[0]; Tb[1][1] = b2[1]; Tb[1][2] = b2[2];
00075 Tb[2][0] = b3[0]; Tb[2][1] = b3[1]; Tb[2][2] = b3[2];
00076
00077 GaussJordan( 3, 0, Tb, Tb );
00078
00079 Ta[0][0] = a1[0]; Ta[0][1] = a1[1]; Ta[0][2] = a1[2];
00080 Ta[1][0] = a2[0]; Ta[1][1] = a2[1]; Ta[1][2] = a2[2];
00081 Ta[2][0] = a3[0]; Ta[2][1] = a3[1]; Ta[2][2] = a3[2];
00082
00083 MMProduct( 3, 3, 3, Tb, Ta, T );
00084
00085 T[3][0] = B[0]; T[3][1] = B[1]; T[3][2] = B[2]; T[3][3] = (U)1;
00086 T[0][3] = T[1][3] = T[2][3] = (U)0;
00087 }
00088
00089 template void CommonCoordinateSystem(
00090 const point<float>& B, const point<float>& P, const point<float>& Ab,
00091 const point<float>& Pb, Ptr< Ptr<float> >& T );
00092 template void CommonCoordinateSystem(
00093 const point<double>& B, const point<double>& P, const point<double>& Ab,
00094 const point<double>& Pb, Ptr< Ptr<double> >& T );
00095 }
00096