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_execNameVolume(void)
00054 {
00055 char name1[15];
00056
00057 while (1 != sscanf(restbuf, "%s", name1))
00058 {
00059 printf("volume: Nome");
00060 if (!lineins("? "))
00061 {
00062 return;
00063 }
00064 }
00065 printf("solido %s tem volume de %f\n", name1, MSD_highNameVolume(name1));
00066 }
00067
00068 real MSD_highNameVolume(char *name)
00069 {
00070 int sn;
00071
00072 if ((sn = MSD_getSolidIdFromName(name)) == -1)
00073 {
00074 fprintf(stderr, MEN_NaoEncontrouSolidNome, NAM_Volume, name);
00075 return(0.0);
00076 }
00077 return(MSD_highVolume(sn));
00078 }
00079
00080 #ifdef __Extended_Version
00081 void MSD_execVolume(void)
00082 {
00083 int sn;
00084
00085 while (1 != sscanf(restbuf, "%d", &sn))
00086 {
00087 printf("volume: sn");
00088 if (!lineins("? "))
00089 {
00090 return;
00091 }
00092 }
00093 printf("solido %d tem volume de %f\n", sn, MSD_highVolume(sn));
00094 }
00095
00096 #endif
00097
00098 real MSD_highVolume(Id sn)
00099 {
00100 SPTYPE s;
00101
00102 if ((s = MSD_getSolid(sn)) == SNIL)
00103 {
00104 fprintf(stderr, MEN_NaoEncontrouSolido, NAM_Volume, sn);
00105 return(0.0);
00106 }
00107 return(MSD_lowVolume(s));
00108 }
00109
00110
00111 real MSD_lowVolume(SPTYPE s)
00112 {
00113 DPTYPE d;
00114 FPTYPE f;
00115 LPTYPE l;
00116 HPTYPE he1;
00117 HPTYPE he2;
00118 VPTYPE v;
00119 vector a, b, c, cent;
00120 double res;
00121 int len;
00122
00123 cent[0] = cent[1] = cent[2] = 0.0;
00124 len = 0;
00125 for (AllShellsSolid(s, d))
00126 {
00127 for (AllVerticesShell(d, v))
00128 {
00129 vecplus(cent, cent, VerVCoord(v));
00130 len++;
00131 }
00132 }
00133 cent[0] = cent[0] / len;
00134 cent[1] = cent[1] / len;
00135 cent[2] = cent[2] / len;
00136 cent[3] = 0.0;
00137
00138 res = 0.0;
00139 for (AllShellsSolid(s, d))
00140 {
00141 for (AllFacesShell(d, f))
00142 {
00143 for (AllLoopsFace(f, l))
00144 {
00145 he1 = LooLEdg(l);
00146 he2 = HalNxt(he1);
00147 do
00148 {
00149 vecminus(a, VerVCoord(HalVtx(he2)), cent);
00150 vecminus(b, VerVCoord(HalVtx(he1)), cent);
00151 cross(c, a, b);
00152 vecminus(b, VerVCoord(HalVtx(HalNxt(he2))), cent);
00153 res += dot(b, c);
00154 } while ((he2 = HalNxt(he2)) != he1);
00155 }
00156 }
00157 }
00158 return(-res / 6.0);
00159 }