Koch curve: Difference between revisions
Content added Content deleted
m (→Python :: Functional: Tidying) |
m (Simplified code) |
||
Line 124: | Line 124: | ||
The output of this program is an SVG file depicting a Koch snowflake. |
The output of this program is an SVG file depicting a Koch snowflake. |
||
<lang cpp>// See https://en.wikipedia.org/wiki/Koch_snowflake |
<lang cpp>// See https://en.wikipedia.org/wiki/Koch_snowflake |
||
#include <cmath> |
|||
#include <fstream> |
#include <fstream> |
||
#include <iostream> |
#include <iostream> |
||
Line 146: | Line 145: | ||
x1 = points[i + 1].x; |
x1 = points[i + 1].x; |
||
y1 = points[i + 1].y; |
y1 = points[i + 1].y; |
||
double |
double dy = y1 - y0; |
||
double |
double dx = x1 - x0; |
||
double cos = std::cos(angle); |
|||
double sin = std::sin(angle); |
|||
output[j].x = x0; |
output[j].x = x0; |
||
output[j].y = y0; |
output[j].y = y0; |
||
output[j + 1].x = x0 + |
output[j + 1].x = x0 + dx/3; |
||
output[j + 1].y = y0 + |
output[j + 1].y = y0 + dy/3; |
||
output[j + 2].x = x0 + |
output[j + 2].x = x0 + dx/2 - dy * r32/3; |
||
output[j + 2].y = y0 + |
output[j + 2].y = y0 + dy/2 + dx * r32/3; |
||
output[j + 3].x = x0 + 2 * |
output[j + 3].x = x0 + 2 * dx/3; |
||
output[j + 3].y = y0 + 2 * |
output[j + 3].y = y0 + 2 * dy/3; |
||
} |
} |
||
output[j].x = x1; |
output[j].x = x1; |