Koch curve: Difference between revisions

177 bytes removed ,  4 years ago
m
Simplified code
m (Simplified code)
Line 124:
The output of this program is an SVG file depicting a Koch snowflake.
<lang cpp>// See https://en.wikipedia.org/wiki/Koch_snowflake
#include <cmath>
#include <fstream>
#include <iostream>
Line 146 ⟶ 145:
x1 = points[i + 1].x;
y1 = points[i + 1].y;
double angledy = std::atan2(y1 - y0, x1 - x0);
double ddx = std::hypot(x1 - x0, y1 - y0);
double cos = std::cos(angle);
double sin = std::sin(angle);
output[j].x = x0;
output[j].y = y0;
output[j + 1].x = x0 + d * cosdx/3;
output[j + 1].y = y0 + d * sindy/3;
output[j + 2].x = x0 + d * cosdx/2 - ddy * r32 * sin/3;
output[j + 2].y = y0 + d * sindy/2 + ddx * r32 * cos/3;
output[j + 3].x = x0 + 2 * d * cosdx/3;
output[j + 3].y = y0 + 2 * d * sindy/3;
}
output[j].x = x1;
1,777

edits