#include <stdio.h> #include <math.h> #define E0 1e-9 #define P 3.1415926 #define m 2 double G(double a[m][m],int n,double b[m]) { int i,j,k,i1,j1; double temp; int row_maxmod; double element_maxmod; for(j=0;j<m;j++) { element_maxmod=a[j][j]; row_maxmod=j; for(i=j+1;i<m;i++) if(fabs(element_maxmod)<fabs(a[i][j])) { element_maxmod=a[i][j]; row_maxmod=i; } if(fabs(element_maxmod)<E0) { printf(系数行列式为零,线性方程组无解!\n); return NULL; } if(row_maxmod!=j) { for(k=j;k<m;k++) { temp=a[j][k]; a[j][k]=a[row_maxmod][k]; a[row_maxmod][k]=temp; } temp=b[j]; b[j]=b[row_maxmod]; b[row_maxmod]=temp; } for(k=j;k<m;k++) a[j][k]/=element_maxmod; b[j]/=element_maxmod; for(i1=j+1;i1<m;i1++) { temp=a[i1][j]; for(j1=j;j1<m;j1++) a[i1][j1]-=a[j][j1]*temp; b[i1]-=b[j]*temp; } } for(i=m-2;i>=0;i--) for(j=1;j>i;j--) b[i]-=a[i][j]*b[j]; return b[n]; } void main() {double p1x=1,p1y=1,p2x=2,p2y=0.5,p3x=3,p3y=1.5,o12=0.0,o13=P/4.0,a0x,a0y; double A[2][2],B[2],V[2]; printf(请输入固定铰点坐标a0x a0y\n); scanf(%lf %lf,&a0x,&a0y); A[0][0]=cos(o12)*(p2x-p1x*cos(o12)+p1y*sin(o12))+sin(o12)*(p2y-p1x*sin(o12)-p1y*cos(o12))+(1-cos(o12))*a0x-sin(o12)*a0y; A[0][1]=-sin(o12)*(p2x-p1x*cos(o12)+p1y*sin(o12))+cos(o12)*(p2y-p1x*sin(o12)-p1y*cos(o12))+(1-cos(o12))*a0y+sin(o12)*a0x; A[1][0]=cos(o13)*(p3x-p1x*cos(o13)+p1y*sin(o13))+sin(o13)*(p3y-p1x*sin(o13)-p1y*cos(o13))+(1-cos(o13))*a0x-sin(o13)*a0y; A[1][1]=-sin(o13)*(p3x-p1x*cos(o13)+p1y*sin(o13))+cos(o13)*(p3y-p1x*sin(o13)-p1y*cos(o13))+(1-cos(o13))*a0y+sin(o13)*a0x; B[0]=(p2x-p1x*cos(o12)+p1y*sin(o12))*a0x+(p2y-p1x*sin(o12)-p1y*cos(o12))*a0y-sin(o12)*sin(o12)/2.0-(p2y-p1x*sin(o12)-p1y*cos(o12))*(p2y-p1x*sin(o12)-p1y*cos(o12))/2.0; B[1]=(p3x-p1x*cos(o13)+p1y*sin(o13))*a0x+(p3y-p1x*sin(o13)-p1y*cos(o13))*a0y-sin(o13)*sin(o13)/2.0-(p3y-p1x*sin(o13)-p1y*cos(o13))*(p3y-p1x*sin(o13)-p1y*cos(o13))/2.0; V[0]=G(A,0,B),V[1]=G(A,1,B); printf(a1x=%lf a1y=%lf\n,V[0],V[1]); } |