00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <stdio.h>
00042 #include "mensagem.h"
00043 #include "memvirtu.h"
00044 #include "lowparam.h"
00045 #include "lowmacro.h"
00046 #include "lowsolid.h"
00047 #include "genfunc_.h"
00048 #include "vectorop.h"
00049 #include "eulerops.h"
00050 #include "analise_.h"
00051 #include "mancommd.h"
00052
00053 void MSD_execNameMatrizInercia(void)
00054 {
00055 char name1[12];
00056 matrix mat;
00057
00058 while (1 != sscanf(restbuf, "%s", name1))
00059 {
00060 printf("matriz inercia: Nome");
00061 if (!lineins("? "))
00062 {
00063 return;
00064 }
00065 }
00066 MSD_highNameMatrizInercia(name1, mat);
00067 printf("solido %s tem matriz de inercia:\n %10.4f %10.4f %10.4f\n", name1,
00068 mat[0][0], mat[0][1], mat[0][2]);
00069 printf(" %10.4f %10.4f %10.4f\n", mat[1][0], mat[1][1], mat[1][2]);
00070 printf(" %10.4f %10.4f %10.4f\n", mat[2][0], mat[2][1], mat[2][2]);
00071 }
00072
00073 int MSD_highNameMatrizInercia(char *name, matrix mat)
00074 {
00075 int sn;
00076
00077 if ((sn = MSD_getSolidIdFromName(name)) == -1)
00078 {
00079 fprintf(stderr, MEN_NaoEncontrouSolidNome, NAM_Inercia, name);
00080 return(ERROR);
00081 }
00082 return(MSD_highMatrizInercia(sn, mat));
00083 }
00084
00085 int MSD_highMatrizInercia(Id sn, matrix mat)
00086 {
00087 SPTYPE s;
00088 vector cg;
00089
00090 if ((s = MSD_getSolid(sn)) == SNIL)
00091 {
00092 fprintf(stderr, MEN_NaoEncontrouSolido, NAM_Inercia, sn);
00093 return(ERROR);
00094 }
00095 MSD_lowCentroDeGravidade(s, cg);
00096 return(MSD_lowMatrizInercia(s, mat, cg));
00097 }
00098
00099
00100 int MSD_lowMatrizInercia(SPTYPE s, matrix mat, vector cg)
00101 {
00102 DPTYPE dg;
00103 FPTYPE f;
00104 LPTYPE l;
00105 HPTYPE he1;
00106 HPTYPE he2;
00107 vector a, b, c, d;
00108 double escalar, intx2, inty2, intz2;
00109 int i, j;
00110
00111 matzer(mat);
00112 intx2 = inty2 = intz2 = 0;
00113
00114 for (AllShellsSolid(s, dg))
00115 {
00116 for (AllFacesShell(dg, f))
00117 {
00118 for (AllLoopsFace(f, l))
00119 {
00120 he1 = LooLEdg(l);
00121 he2 = HalNxt(he1);
00122 do
00123 {
00124 vecminus(a, VerVCoord(HalVtx(he2)), cg);
00125 vecminus(b, VerVCoord(HalVtx(he1)), cg);
00126 cross(c, a, b);
00127 vecminus(d, VerVCoord(HalVtx(HalNxt(he2))), cg);
00128 escalar = dot(d, c);
00129 intx2 = escalar * (a[0] * a[0] + b[0] * b[0] + d[0] * d[0] +
00130 a[0] * b[0] + a[0] * d[0] + b[0] * d[0]);
00131 inty2 = escalar * (a[1] * a[1] + b[1] * b[1] + d[1] * d[1] +
00132 a[1] * b[1] + a[1] * d[1] + b[1] * d[1]);
00133 intz2 = escalar * (a[2] * a[2] + b[2] * b[2] + d[2] * d[2] +
00134 a[2] * b[2] + a[2] * d[2] + b[2] * d[2]);
00135 mat[0][0] += inty2 + intz2;
00136 mat[1][1] += intx2 + intz2;
00137 mat[2][2] += intx2 + inty2;
00138 mat[0][1] += escalar *
00139 (a[0] * a[1] + b[0] * b[1] + d[0] * d[1] +
00140 0.5 * (a[0] * b[1] + a[0] * d[1] + b[0] * a[1] +
00141 b[0] * d[1] + d[0] * a[1] + d[0] * b[1]));
00142 mat[0][2] += escalar *
00143 (a[0] * a[2] + b[0] * b[2] + d[0] * d[2] +
00144 0.5 * (a[0] * b[2] + a[0] * d[2] + b[0] * a[2] +
00145 b[0] * d[2] + d[0] * a[2] + d[0] * b[2]));
00146 mat[1][2] += escalar *
00147 (a[1] * a[2] + b[1] * b[2] + d[1] * d[2] +
00148 0.5 * (a[1] * b[2] + a[1] * d[2] + b[1] * a[2] +
00149 b[1] * d[2] + d[1] * a[2] + d[1] * b[2]));
00150 } while ((he2 = HalNxt(he2)) != he1);
00151 }
00152 }
00153 }
00154 mat[2][1] = mat[1][2];
00155 mat[1][0] = mat[0][1];
00156 mat[2][0] = mat[0][2];
00157
00158 for (i = 0; i < 3; i++)
00159 {
00160 for (j = 0; j < 3; j++)
00161 {
00162 mat[i][j] *= SolDensRel(s) / 60.0;
00163 if (i == j)
00164 {
00165 mat[i][j] *= -1.0;
00166 }
00167 }
00168 }
00169 return(SUCCESS);
00170 }