mirror of
git://projects.qi-hardware.com/ben-scans.git
synced 2024-11-22 08:49:42 +02:00
Fix our trigonometry: the z0 inclination is expressed as a tangent, not a sine.
- solidify/project.c (read_face_data, save_face_data): fx/fy represent a tangent, not a sine - solidify/overlap.c (merge_matrix): corrected shrinkage formula to use tangent instead of sine
This commit is contained in:
parent
286a6bdd09
commit
98b6050e83
@ -169,12 +169,19 @@ static void merge_matrix(struct matrix *m, const struct solid *s,
|
|||||||
m->b[1] += f->cy;
|
m->b[1] += f->cy;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Apply shrinkage caused by rotation out of z0. We use that
|
* Apply shrinkage caused by rotation out of z0.
|
||||||
* cos a = sqrt(1-sin^2 a)
|
* We need to divide by x = cos a. We have f = tan a.
|
||||||
|
* With sin^2 a + cos^2 a = 1, we get
|
||||||
|
*
|
||||||
|
* f = sqrt(1-cos^2 a)/cos a
|
||||||
|
* = sqrt(1-x^2)/x
|
||||||
|
* f^2 = 1/x^2-1
|
||||||
|
* 1/(f^2+1) = x^2
|
||||||
|
* cos a = sqrt(1/(f^2+1))
|
||||||
*/
|
*/
|
||||||
|
|
||||||
f_x = 1.0/sqrt(1-f->fx*f->fx);
|
f_x = sqrt(f->fx*f->fx+1);
|
||||||
f_y = 1.0/sqrt(1-f->fy*f->fy);
|
f_y = sqrt(f->fy*f->fy+1);
|
||||||
|
|
||||||
m->a[0][0] *= f_x;
|
m->a[0][0] *= f_x;
|
||||||
m->a[0][1] *= f_x;
|
m->a[0][1] *= f_x;
|
||||||
|
@ -71,11 +71,11 @@ static void read_face_data(FILE *file, struct face *f)
|
|||||||
|
|
||||||
if (fscanf(file, "%f", &v) != 1)
|
if (fscanf(file, "%f", &v) != 1)
|
||||||
return;
|
return;
|
||||||
f->fx = sin(v/180*M_PI);
|
f->fx = tan(v/180*M_PI);
|
||||||
|
|
||||||
if (fscanf(file, "%f", &v) != 1)
|
if (fscanf(file, "%f", &v) != 1)
|
||||||
return;
|
return;
|
||||||
f->fy = sin(v/180*M_PI);
|
f->fy = tan(v/180*M_PI);
|
||||||
|
|
||||||
if (fscanf(file, "%f", &v) != 1)
|
if (fscanf(file, "%f", &v) != 1)
|
||||||
return;
|
return;
|
||||||
@ -152,7 +152,7 @@ static void save_face_data(FILE *file, const char *name, const struct face *f)
|
|||||||
a = 180-a;
|
a = 180-a;
|
||||||
if (fprintf(file, "%g %g %g\n%g %g %g\n",
|
if (fprintf(file, "%g %g %g\n%g %g %g\n",
|
||||||
f->z_ref*f->z_step,
|
f->z_ref*f->z_step,
|
||||||
asin(f->fx)/M_PI*180, asin(f->fy)/M_PI*180,
|
atan(f->fx)/M_PI*180, atan(f->fy)/M_PI*180,
|
||||||
a, f->m.b[0]*f->x_step, f->m.b[1]*f->y_step) < 0) {
|
a, f->m.b[0]*f->x_step, f->m.b[1]*f->y_step) < 0) {
|
||||||
perror(name);
|
perror(name);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
Loading…
Reference in New Issue
Block a user