drl2gp/drl2gp.c |
137 | 137 | } |
138 | 138 | |
139 | 139 | |
| 140 | static double arc2angle(double arc, double r) |
| 141 | { |
| 142 | return acos(1-arc*arc/(r*r)/2); |
| 143 | } |
| 144 | |
| 145 | |
| 146 | static void half_circle(double cx, double cy, double rx, double ry, double s) |
| 147 | { |
| 148 | double m[4]; |
| 149 | double x = rx, y = ry, tmp; |
| 150 | double a; |
| 151 | |
| 152 | m[0] = cos(s); |
| 153 | m[1] = -sin(s); |
| 154 | m[2] = -m[1]; |
| 155 | m[3] = m[0]; |
| 156 | |
| 157 | for (a = 0; a < M_PI; a += s) { |
| 158 | printf("%f %f %f\n", cx+x, cy+y, -depth); |
| 159 | tmp = x*m[0]+y*m[1]; |
| 160 | y = x*m[2]+y*m[3]; |
| 161 | x = tmp; |
| 162 | } |
| 163 | printf("%f %f %f\n", cx-rx, cy-ry, -depth); |
| 164 | } |
| 165 | |
| 166 | |
140 | 167 | static void slot(double xa, double ya, double xb, double yb, double d) |
141 | 168 | { |
| 169 | double dx = xb-xa; |
| 170 | double dy = yb-ya; |
| 171 | double cr = d/2; |
| 172 | double tr = d0/2; |
| 173 | double s = arc2angle(MAX_STEP, cr); |
| 174 | double nx, ny; |
| 175 | double f; |
| 176 | |
142 | 177 | assert(mill); |
| 178 | f = (cr-tr)/hypot(dx, dy); |
| 179 | nx = -dy*f; |
| 180 | ny = dx*f; |
| 181 | |
| 182 | half_circle(xa, ya, nx, ny, s); |
| 183 | half_circle(xb, yb, -nx, -ny, s); |
| 184 | printf("%f %f %f\n\n", xa+nx, ya+ny, -depth); |
143 | 185 | } |
144 | 186 | |
145 | 187 | |
... | ... | |
147 | 189 | { |
148 | 190 | double cr = d/2; |
149 | 191 | double tr = d0/2; |
150 | | double s = acos(1-MAX_STEP*MAX_STEP/(cr*cr)/2); |
| 192 | double s = arc2angle(MAX_STEP, cr); |
151 | 193 | double a; |
152 | 194 | |
153 | 195 | assert(mill); |