def towards(self, bot, target: Vec3, time: float, allowed_uncertainty: float = 0.3, dodge_hit: bool = True): ball_soon = ball_predict(bot, time) ball_soon_to_target_dir = normalize(target - ball_soon.pos) right = dot(axis_to_rotation(Vec3(z=allowed_uncertainty)), ball_soon_to_target_dir) left = dot(axis_to_rotation(Vec3(z=-allowed_uncertainty)), ball_soon_to_target_dir) aim_cone = AimCone(right, left) aim_cone.draw(ball_soon.pos, r=0, g=0) return self.with_aiming(bot, aim_cone, time, dodge_hit)
def draw_circle(bot, center: Vec3, normal: Vec3, radius: float, pieces: int): # Construct the arm that will be rotated arm = normalize(cross(normal, center)) * radius angle = 2 * math.pi / pieces rotation_mat = axis_to_rotation(angle * normalize(normal)) points = [center + arm] for i in range(pieces): arm = dot(rotation_mat, arm) points.append(center + arm) bot.renderer.draw_polyline_3d(points, bot.renderer.orange())
def circle(self, center: Vec3, normal: Vec3, radius: float, color): # Construct the arm that will be rotated pieces = int(radius**0.7) + 5 arm = normalize(vec.cross(normal, center)) * radius angle = 2 * math.pi / pieces rotation_mat = axis_to_rotation(angle * normalize(normal)) points = [center + arm] for i in range(pieces): arm = dot(rotation_mat, arm) points.append(center + arm) self.renderer.draw_polyline_3d(points, color)
import math from utility.info import Field from utility.vec import Vec3, axis_to_rotation, vec_max, norm, max_comp, dot, normalize ROUNDNESS = 300.0 SEMI_SIZE = Field.SIZE / 2 CORNER_SEMI_SIZE = Vec3( math.cos(math.pi / 4) * Field.CORNER_WALL_AX_INTERSECT, math.cos(math.pi / 4) * Field.CORNER_WALL_AX_INTERSECT, Field.HEIGHT / 2) GOALS_SEMI_SIZE = Vec3(1786 / 2, Field.LENGTH / 2 + 880, Field.GOAL_HEIGHT / 2) ROT_45_MAT = axis_to_rotation(Vec3(z=1) * math.pi / 4) def sdf_wall_dist(point: Vec3) -> float: """ Returns the distance to the nearest wall of using an SDF approximation. The result is negative if the point is outside the arena. """ # SDF box https://www.youtube.com/watch?v=62-pRVZuS5c # SDF rounded corners https://www.youtube.com/watch?v=s5NGeUV2EyU ONES = Vec3(1, 1, 1) # Base cube base_q = abs(point - Vec3(z=Field.HEIGHT / 2)) - SEMI_SIZE + ONES * ROUNDNESS base_dist_outside = norm(vec_max(base_q, Vec3()))