//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "Rotation.h" #define min(a, b) (((a) < (b)) ? (a) : (b)) #define max(a, b) (((a) > (b)) ? (a) : (b)) //--------------------------------------------------------------------------- #pragma package(smart_init) //--------------------------------------------------------------------------- __fastcall TPRotation::TPRotation() { init(); } //--------------------------------------------------------------------------- __fastcall TPRotation::~TPRotation() { } //--------------------------------------------------------------------------- void __fastcall TPRotation::init() { T[0][0] = 1.0; T[0][1] = 0.0; T[0][2] = 0.0; T[1][0] = 0.0; T[1][1] = 1.0; T[1][2] = 0.0; T[2][0] = 0.0; T[2][1] = 0.0; T[2][2] = 1.0; } //--------------------------------------------------------------------------- void __fastcall TPRotation::scaling(Extended x, Extended y) { Extended t[3][3]; t[0][0] = T[0][0]*x; t[0][1] = T[0][1]*y; t[0][2] = T[0][2]; t[1][0] = T[1][0]*x; t[1][1] = T[1][1]*y; t[1][2] = T[1][2]; t[2][0] = T[2][0]*x; t[2][1] = T[2][1]*y; t[2][2] = T[2][2]; memcpy(T[0], t[0], 9*sizeof(Extended)); } //--------------------------------------------------------------------------- void __fastcall TPRotation::translation(Extended x, Extended y) { Extended t[3][3]; t[0][0] = T[0][0]+T[0][2]*x; t[0][1] = T[0][1]+T[0][2]*y; t[0][2] = T[0][2]; t[1][0] = T[1][0]+T[1][2]*x; t[1][1] = T[1][1]+T[1][2]*y; t[1][2] = T[1][2]; t[2][0] = T[2][0]+T[2][2]*x; t[2][1] = T[2][1]+T[2][2]*y; t[2][2] = T[2][2]; memcpy(T[0], t[0], 9*sizeof(Extended)); } //--------------------------------------------------------------------------- void __fastcall TPRotation::rotation(Extended theta) { Extended t[3][3], st = sin(theta), ct =cos(theta); if(st > 0.9999999) st = 1; //added by qe (2001. 1) if(st > -0.001 && st < 0.001) st = 0; //Á¤¹Ðµµ ¹®Á¦ ¶§¹®¿¡.. if(st < -0.9999999) st = -1; //ex) sin90 ÀÌ 1ÀÌ ¾È³ª¿À´Â °æ¿ì°¡ À־.. if(ct > 0.9999999) ct = 1; if(ct > -0.001 && ct < 0.001) ct = 0; if(ct < -0.9999999) ct = -1; t[0][0] = T[0][0]*ct-T[0][1]*st; t[0][1] = T[0][0]*st+T[0][1]*ct; t[0][2] = T[0][2]; t[1][0] = T[1][0]*ct-T[1][1]*st; t[1][1] = T[1][0]*st+T[1][1]*ct; t[1][2] = T[1][2]; t[2][0] = T[2][0]*ct-T[2][1]*st; t[2][1] = T[2][0]*st+T[2][1]*ct; t[2][2] = T[2][2]; memcpy(T[0], t[0], 9*sizeof(Extended)); } //--------------------------------------------------------------------------- void __fastcall TPRotation::convert(Extended &ox, Extended &oy) { Extended ix = ox, iy = oy; ox = T[0][0]*ix+T[1][0]*iy+T[2][0]; oy = T[0][1]*ix+T[1][1]*iy+T[2][1]; } //--------------------------------------------------------------------------- void __fastcall TPRotation::convert(Extended ix, Extended iy, Extended &ox, Extended &oy) { ox = T[0][0]*ix+T[1][0]*iy+T[2][0]; oy = T[0][1]*ix+T[1][1]*iy+T[2][1]; } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- __fastcall TRim::TRim() { } //--------------------------------------------------------------------------- __fastcall TRim::~TRim() { } //--------------------------------------------------------------------------- void __fastcall TRim::init(int h, Extended sdegree, Extended edegree, Extended ss, Extended sl, Extended es, Extended el) { ssR = ss; slR = sl; esR = es; elR = el; sDegree = sdegree; eDegree = edegree; if ((eDegree-sDegree)>M_PI) e_s = (eDegree-sDegree)-2*M_PI; else if ((eDegree-sDegree)<-M_PI) e_s = (eDegree-sDegree)+2*M_PI; else e_s = eDegree-sDegree; Width = (ss + sl + es + el)/4*fabs(edegree-sdegree) + 1; Height = h-1; int i, j; max_x = min_x = max_y = min_y = 0; for (i=-4; i<4; i++) { if (e_s >= 0) { if ( sDegree<=M_PI_2*i && (sDegree+e_s)>=M_PI_2*i ) { j = i + 4; switch (j%4) { case 1 : max_y = max(slR, elR); break; case 2 : min_x = -max(slR, elR); break; case 3 : min_y = -max(slR, elR); break; case 0 : max_x = max(slR, elR); break; } } } else { if ( (sDegree+e_s)<=M_PI_2*i && sDegree>=M_PI_2*i ) { j = i + 4; switch (j%4) { case 1 : max_y = max(slR, elR); break; case 2 : min_x = -max(slR, elR); break; case 3 : min_y = -max(slR, elR); break; case 0 : max_x = max(slR, elR); break; } } } } if (max_x==0) max_x=max(max(slR*cos(sDegree), elR*cos(eDegree)), max(ssR*cos(sDegree), esR*cos(eDegree))); if (min_x==0) min_x=min(min(slR*cos(sDegree), elR*cos(eDegree)), min(ssR*cos(sDegree), esR*cos(eDegree))); if (max_y==0) max_y=max(max(slR*sin(sDegree), elR*sin(eDegree)), max(ssR*sin(sDegree), esR*sin(eDegree))); if (min_y==0) min_y=min(min(slR*sin(sDegree), elR*sin(eDegree)), min(ssR*sin(sDegree), esR*sin(eDegree))); } //--------------------------------------------------------------------------- void __fastcall TRim::translation(Extended x, Extended y) { X = x; Y = y; } //--------------------------------------------------------------------------- bool __fastcall TRim::convert(Extended ix, Extended iy, Extended &ox, Extended &oy) { Extended theta, sR, lR, delta; iy -= Y; ix -= X; if (ix) { if (iy>=0 && ix>=0) theta = atanl(iy/ix); if (iy<0 && ix>=0) theta = atanl(iy/ix); if (iy>=0 && ix<0) theta = M_PI+atanl(iy/ix); if (iy<0 && ix<0) theta = -M_PI+atanl(iy/ix); } else { if (iy>=0) theta = M_PI_2; else theta = -M_PI_2; } delta = theta-sDegree; if (delta>M_PI) delta = delta-2*M_PI; else if (delta<-M_PI) delta = delta+2*M_PI; if ( ((e_s-delta)>0) && (delta<0) ) return false; ox = delta * Width / e_s; lR = (delta*elR + (e_s-delta)*slR) / e_s; sR = (delta*esR + (e_s-delta)*ssR) / e_s; oy = Height * (lR - sqrt(ix*ix + iy*iy)) / (lR - sR); if (oy>Height || oy<0) return false; return true; } //---------------------------------------------------------------------------