def add_circular_arc_perturbed(self, n, cx, cy, delta_theta, r0, r1, perturb_r0, perturb_r1): r = (cx**2 + cy**2)**0.5 t = degrees(atan2(cy, cx)) x, y = self.circular_arc(n, r, delta_theta) x, y = Layout.rotate_coords(x, y, t) # Linear scaling # scale = perturb_r0 + (perturb_r1 - perturb_r0) * ((r - r0) / (r1 - r0)) # Log scaling a = r1 - r b = r - r0 f = b / (a + b) scale = perturb_r1**f * perturb_r0**(1 - f) # print(r0, r1, perturb_r0, perturb_r1, r, scale) for i in range(len(x)): t = np.random.rand() * 2 * np.pi rt = np.random.rand() * scale x[i] += rt * cos(t) y[i] += rt * sin(t) self.layouts[self._get_key('circular_arc_p')] = { 'x': x, 'y': y, 'cx': cx, 'cy': cy }
def add_circular_arc(self, n, cx, cy, delta_theta): r = (cx**2 + cy**2)**0.5 t = degrees(atan2(cy, cx)) x, y = self.circular_arc(n, r, delta_theta) x, y = Layout.rotate_coords(x, y, t) self.layouts[self._get_key('circular_arc')] = { 'x': x, 'y': y, 'cx': cx, 'cy': cy }
def symmetric_log_spiral(n, r0, r1, b, num_arms, theta0_deg): """Add log spiral arms (each arm identical and rotated.)""" x, y = TelescopeLayout.log_spiral(n, r0, r1, b) d_theta = 360 / num_arms x_final = np.zeros(n * num_arms) y_final = np.zeros(n * num_arms) for arm in range(num_arms): x_, y_ = Layout.rotate_coords(x, y, theta0_deg + d_theta * arm) x_final[arm * n:(arm + 1) * n] = x_ y_final[arm * n:(arm + 1) * n] = y_ return x_final, y_final
def log_spiral_arms_2(n, r0, r1, b, num_arms, theta0_deg): """Add log spiral arms (constructed from a single spiral)""" x, y = TelescopeLayout.log_spiral(n * num_arms, r0, r1, b) d_theta = 360 / num_arms x_final = np.zeros(n * num_arms) y_final = np.zeros(n * num_arms) for arm in range(num_arms): x_, y_ = Layout.rotate_coords(x[arm::num_arms], y[arm::num_arms], theta0_deg + d_theta * arm) x_final[arm * n:(arm + 1) * n] = x_ y_final[arm * n:(arm + 1) * n] = y_ return x_final, y_final
def add_log_spiral_3(self, n, r0_ref, r0, r1, b, num_arms, theta0_deg): x, y = self.log_spiral_2(n * num_arms, r0_ref, r0, r1, b) d_theta = 360 / num_arms x_final = np.zeros(n * num_arms) y_final = np.zeros(n * num_arms) for arm in range(num_arms): x_, y_ = Layout.rotate_coords(x[arm::num_arms], y[arm::num_arms], theta0_deg + d_theta * arm) x_final[arm * n:(arm + 1) * n] = x_ y_final[arm * n:(arm + 1) * n] = y_ keys = self.layouts.keys() self.layouts['log_spiral_arms' + str(len(keys))] = { 'x': x_final, 'y': y_final, 'r_min': r0, 'r_max': r1, 'r_ref': r0_ref }
def add_log_spiral_section(self, n, r0_ref, cx, cy, b, delta_theta, theta0_deg, theta_offset=0): r0, r1 = self.r_range_for_centre(cx, cy, r0_ref, delta_theta, b, theta_offset) x, y = self.log_spiral_2(n, r0_ref, r0, r1, b) x, y = Layout.rotate_coords(x, y, theta0_deg) keys = self.layouts.keys() self.layouts['log_spiral_section' + str(len(keys))] = { 'x': x, 'y': y, 'cx': cx, 'cy': cy, 'r_min': r0, 'r_max': r1 }
def spiral_to_arms(x, y, num_arms, theta0_deg): d_theta = 360 / num_arms for i in range(num_arms): x[i::num_arms], y[i::num_arms] = Layout.rotate_coords( x[i::num_arms], y[i::num_arms], theta0_deg + d_theta * i) return x, y