Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void ct_draw_poly(
- ct::plot2d& plot,
- ct_complex origin,
- double radius,
- double start_angle,
- unsigned int n
- ) {
- double abase = CT_PI2 / n;
- plot.circle(origin, radius, CT_RGBF(0, 1, 0));
- for (unsigned int i = 0; i < n; ++i)
- {
- double angle_0 = abase * i + start_angle;
- double angle_1 = angle_0 + abase;
- ct_complex p0_raw = {
- cos(angle_0) * radius,
- sin(angle_0) * radius
- };
- ct_complex p1_raw = {
- cos(angle_1) * radius,
- sin(angle_1) * radius
- };
- ct_complex p0_proj = origin + p0_raw;
- ct_complex p1_proj = origin + p1_raw;
- plot.line(p0_proj, p1_proj, CT_RGBF(1, 0, 0));
- }
- }
- void ct_bearing(
- ct::plot2d& plot,
- unsigned int r_i,
- unsigned int r_max,
- ct_complex origin,
- double origin_radius,
- double start_angle,
- unsigned int n
- ) {
- if (r_i >= r_max) return;
- // BASE ANGLE
- double ball_abase = CT_PI2 / n;
- // BALL SCALE
- ct_complex d0 = {
- origin.real() + origin_radius,
- origin.imag()
- };
- ct_complex d1 = {
- origin.real() + cos(ball_abase) * origin_radius,
- origin.imag() + sin(ball_abase) * origin_radius
- };
- double ball_diameter = abs(d1 - d0);
- double ball_radius = ball_diameter / 2;
- double ball_scale = origin_radius / (origin_radius + ball_radius);
- double ball_inner_radius = origin_radius - ball_diameter * ball_scale;
- //plot.circle(origin, ball_inner_radius, CT_RGBF(0, 1, 1));
- double scale_ball_inner_radius = ball_inner_radius * 1.5;
- ct_bearing(plot, r_i + 1, r_max, origin, scale_ball_inner_radius, start_angle + ball_abase / 2, n);
- for (unsigned int i = 0; i < n; ++i)
- {
- double ball_angle_0 = ball_abase * i + start_angle;
- ct_complex p0 = {
- cos(ball_angle_0) * origin_radius,
- sin(ball_angle_0) * origin_radius
- };
- ct_complex ball_proj_p0 = origin + p0 * ball_scale;
- double ball_proj_radius = ball_radius * ball_scale;
- double scale_ball_radius = ball_proj_radius * 1.03;
- //plot.circle(ball_proj_p0, scale_ball_radius, CT_RGBF(1, 0, 0));
- if (r_i == r_max - 1)
- {
- ct_draw_poly(plot, ball_proj_p0, scale_ball_radius, ball_angle_0, n);
- }
- ct_bearing(plot, r_i + 1, r_max, ball_proj_p0, scale_ball_radius, ball_angle_0, n);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement