void rotate_z(float m[3][3], float r) { m[0][0]=mcos(r); m[0][1]=-msin(r); m[0][2]=0; m[1][0]=msin(r); m[1][1]=mcos(r); m[1][2]=0; m[2][0]=0; m[2][1]=0; m[2][2]=1; }
float mcos(float x) { x+=PI/2; if (x>PI/2) { x=PI-x; } return msin(x); }
void Matrix::zrotate (float t) { float st=msin(t), ct=mcos(t); clear (); /* | cos t -sin t 0 | Mr = | sin t cos t 0 | | 0 0 0 | */ m[10] = m[15] = 1.0f; m[0] = ct; m[1] = -st; m[4] = st; m[5] = ct; }
void Matrix::xrotate (float t) { float st = msin(t), ct = mcos(t); clear (); /* | 1 0 0 | Mr = | 0 cos t -sin t | | 0 sin t cos t | */ m[0] = 1.0f; m[5] = ct; m[6] = -st; m[9] = st; m[10] = ct; m[15] = 1.0f; }
void Matrix::yrotate (float t) { float st=msin(t), ct=mcos(t); clear (); /* | cos t 0 -sin t | Mr = | 0 1 0 | | sin t 0 cos t | */ m[0] = ct; m[2] = -st; m[5] = 1.0f; m[8] = st; m[10] = ct; m[15] = 1.0f; }
int main () { double o,ee,input;int c; for(;;){ printf("-----------------------------------------\n1. Input positive number\n2. Caculate sine x\n3. Caculate square root\n4. Caculate e*x\n5. Quit\n\tYour Answer :");scanf("%d",&c);printf("-----------------------------------------\n"); switch(c){ case 1: printf("-----------------------------------------\nInput positive number :");scanf("%lf",&o); printf("Input error in approximation :");scanf("%lf",&ee);printf("-----------------------------------------\n");break; case 3: printf("-----------------------------------------\n"); if (o < 0) {printf("-----------------------------------------\nCan't Caculate suqare root of negative number !\n-----------------------------------------\n");break;} printf("square root of %.5f = %.5f\n",o,msqrt(o,ee));printf("-----------------------------------------\n");break; case 2: input = o; if( input >= 2*PI) while( input >= 2*PI) input = input - 2*PI; printf("sin(%.5lf) = %.5lf\n",o,msin(input,ee));printf("-----------------------------------------\n");break; case 4: printf("e^%.5lf = %.5f\n",o,mex(o,ee));printf("-----------------------------------------\n");break; case 5:return 0; }}}
void demo() { setgr(); source1=loadgpi("cool.gpi",0); readgpipal("cool.pal",0,255,0); char bol=1; int el[50]; int t=0,y; float temp; for(temp=1;temp<180;temp+=0.1388) { if(y!=(int)(50*mcos(temp))) { y=(int)(50*mcos(temp)); el[t]=(int)(*source1*msin(temp)/2); if(t<50)t++; } } int kur[50]; for(t=0;t<50;t++)kur[t]=*source1; while(bol==1) { clearpot(0); bol=0; for(t=1;t<50;t++) { hsline(160-kur[t],160+kur[t],50+t,source1+*source1*t+2,*source1-1); hsline(160-kur[t],160+kur[t],50+99-t,source1+*source1*(99-t)+2,*source1-1); if(kur[t]>el[t]) { bol=1; kur[t]--; } } // delay(100); } free(source1); }
void Matrix::vector_rotation (const Vector3& cv, float angle) { float c = mcos(angle); float s = msin(angle); float cc = 1 - c; clear (); Vector3 axis(cv); axis.normalize (); v(0,0) = (cc * axis.x * axis.x) + c; v(0,1) = (cc * axis.x * axis.y) + (axis.z * s); v(0,2) = (cc * axis.x * axis.z) - (axis.y * s); v(1,0) = (cc * axis.x * axis.y) - (axis.z * s); v(1,1) = (cc * axis.y * axis.y) + c; v(1,2) = (cc * axis.z * axis.y) + (axis.x * s); v(2,0) = (cc * axis.x * axis.z) + (axis.y * s); v(2,1) = (cc * axis.y * axis.z) - (axis.x * s); v(2,2) = (cc * axis.z * axis.z) + c; }
double mcos(double x){ return msin(PI/2-x); }
double msin(double x){ return (x>PI)?msin(x-2*PI):(x<0?-msin(-x):(x<PI/2?(x-pow(x,3)/6+pow(x,5)/120):(-x+PI+pow(x-PI,3)/6 - pow(x-PI,5)/120))); }