"SfR Fresh" - the SfR Freeware/Shareware Archive 
Member "ocre-0.029/ocre/src/ajustePlano.c" of archive ocre_v0_029.tgz:
As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers.
Alternatively you can here view or download the uninterpreted source code file.
That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
1
2 #include <math.h>
3 #include <stdlib.h>
4 #include <stdio.h>
5
6 #include "ajustePlano.h"
7
8 void acerosdAjustePlano (tajup ajup)
9 {
10 ajup->n = 0;
11 ajup->sx = 0.0; ajup->sy = 0.0; ajup->sz = 0.0;
12 ajup->sxy = 0.0; ajup->sxz = 0.0; ajup->syz = 0.0;
13 ajup->sx2 = 0.0; ajup->sy2 = 0.0; ajup->sz2 = 0.0;
14 ajup->az = 0.0; ajup->bz = 0.0; ajup->cz = 0.0;
15 }
16
17 void nuevodAjustePlano (tajup * najup)
18 {
19 tajup ajup;
20 ajup = (tajup) malloc (sizeof(struct teajup));
21 acerosdAjustePlano (ajup);
22 *najup = ajup ;
23 }
24
25 void borradAjustePlano (tajup ajup)
26 {
27 free (ajup);
28 }
29
30 void imprimedAjustePlano (tajup ajup)
31 {
32 printf ("n: %5d\n", ajup->n);
33 printf ("sx: %9.3f\n", ajup->sx);
34 printf ("sy: %9.3f\n", ajup->sy);
35 printf ("sz: %9.3f\n", ajup->sz);
36 printf ("sxy: %9.3f\n", ajup->sxy);
37 printf ("sxz: %9.3f\n", ajup->sxz);
38 printf ("syz: %9.3f\n", ajup->syz);
39 printf ("sx2: %9.3f\n", ajup->sx2);
40 printf ("sy2: %9.3f\n", ajup->sy2);
41 printf ("sz2: %9.3f\n", ajup->sz2);
42 printf ("az: %9.4f\n", ajup->az);
43 printf ("bz: %9.4f\n", ajup->bz);
44 printf ("cz: %9.4f\n", ajup->cz);
45 printf ("\n");
46 }
47
48 void anyadedAAjustePlano (tajup ajup, int x, int y, int z)
49 {
50 ajup->n += 1 ;
51 ajup->sx += x ; ajup->sy += y ; ajup->sz += z ;
52 ajup->sxy += x * y ; ajup->sxz += x * z ; ajup->syz += y * z ;
53 ajup->sx2 += x * x ; ajup->sy2 += y * y ; ajup->sz2 += z * z ;
54 }
55
56 void calculaAjustePlano (tajup ajup)
57 {
58 double delz;
59 delz = ajup->sx2 * (ajup->sy * ajup->sy - ajup->n * ajup->sy2)
60 + ajup->sx * ajup->sx * ajup->sy2
61 - 2 * ajup->sx * ajup->sy * ajup->sxy
62 + ajup->n * ajup->sxy * ajup->sxy ;
63 ajup->az = - ( ajup->sx * (ajup->sy * ajup->syz - ajup->sy2 * ajup->sz)
64 + ajup->sxy * (ajup->sy * ajup->sz - ajup->n * ajup->syz)
65 + (ajup->n * ajup->sy2 - ajup->sy * ajup->sy) * ajup->sxz
66 ) / delz ;
67 ajup->bz = ( ajup->sx2 * (ajup->sy * ajup->sz - ajup->n * ajup->syz)
68 + ajup->sx * ajup->sx * ajup->syz
69 + (ajup->n * ajup->sxy - ajup->sx * ajup->sy) * ajup->sxz
70 - ajup->sx * ajup->sxy * ajup->sz
71 ) / delz ;
72 ajup->cz = - ( ajup->sx2 * (ajup->sy2 * ajup->sz - ajup->sy * ajup->syz)
73 + ajup->sx * ajup->sxy * ajup->syz
74 + (ajup->sxy * ajup->sy - ajup->sx * ajup->sy2) * ajup->sxz
75 - ajup->sxy * ajup->sxy * ajup->sz
76 ) / delz ;
77 }
78
79 double distanciaAPlano (tajup ajup, int x, int y, int z)
80 {
81 return (z - (ajup->az*x + ajup->bz*y + ajup->cz)) ;
82 }