Root/
| 1 | /* |
| 2 | * face.h - Data structure and handling of one face of a part |
| 3 | * |
| 4 | * Written 2010 by Werner Almesberger |
| 5 | * Copyright 2010 by Werner Almesberger |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | #ifndef FACE_H |
| 14 | #define FACE_H |
| 15 | |
| 16 | #include <math.h> |
| 17 | |
| 18 | #include "array.h" |
| 19 | #include "matrix.h" |
| 20 | |
| 21 | |
| 22 | struct face { |
| 23 | struct array *a; |
| 24 | double x_step, y_step, z_step; |
| 25 | int sx, sy, sz; /* size */ |
| 26 | int cx, cy; /* center */ |
| 27 | int z_ref; |
| 28 | double fx, fy; /* inclination factor */ |
| 29 | struct matrix m; |
| 30 | }; |
| 31 | |
| 32 | |
| 33 | static inline double face_z0(const struct face *f, int x, int y) |
| 34 | { |
| 35 | return f->z_ref+f->fx*(x-f->sx/2)+f->fy*(y-f->sy/2); |
| 36 | } |
| 37 | |
| 38 | |
| 39 | static inline double z0_scale(const struct face *f) |
| 40 | { |
| 41 | return f->z_step/f->x_step; |
| 42 | } |
| 43 | |
| 44 | |
| 45 | static inline double fx_to_angle(const struct face *f) |
| 46 | { |
| 47 | return atan(f->fx*z0_scale(f))/M_PI*180; |
| 48 | } |
| 49 | |
| 50 | |
| 51 | static inline double fy_to_angle(const struct face *f) |
| 52 | { |
| 53 | return atan(f->fy*z0_scale(f))/M_PI*180; |
| 54 | } |
| 55 | |
| 56 | |
| 57 | static inline void fx_from_angle(struct face *f, double a) |
| 58 | { |
| 59 | f->fx = tan(a/180*M_PI)/z0_scale(f); |
| 60 | } |
| 61 | |
| 62 | |
| 63 | static inline void fy_from_angle(struct face *f, double a) |
| 64 | { |
| 65 | f->fy = tan(a/180*M_PI)/z0_scale(f); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | struct face *read_face(const char *name); |
| 70 | |
| 71 | #endif /* !FACE_H */ |
| 72 |
Branches:
master
