Autonomous Racing  1
f1tenth Project Group of Technical University Dortmund, Germany
circle.py
Go to the documentation of this file.
1 
2 import numpy as np
3 from math import atan2
4 from collections import namedtuple
5 
6 from circle_fit import hyper_fit
7 
8 Point = namedtuple("Point", ["x", "y"])
9 
10 
11 class Circle():
12  def __init__(self, center, radius):
13  self.center = center
14  self.radius = radius
15 
16  def create_array(self, start_angle, end_angle, sample_count=50):
17  points = np.zeros((sample_count, 2))
18  angles = np.linspace(start_angle, end_angle, sample_count)
19  points[:, 0] = self.center.x + np.sin(angles) * self.radius
20  points[:, 1] = self.center.y + np.cos(angles) * self.radius
21  return points
22 
23  def get_angle(self, point):
24  return atan2(point.x - self.center.x, point.y - self.center.y)
25 
26  def get_closest_point(self, point):
27  x = point.x - self.center.x
28  y = point.y - self.center.y
29  distance = (x**2 + y**2) ** 0.5
30  return Point(
31  self.center.x + x * self.radius / distance,
32  self.center.y + y * self.radius / distance
33  )
34 
35  @staticmethod
36  def fit(points):
37  center_x, center_y, radius, _ = hyper_fit(points)
38  return Circle(Point(center_x, center_y), radius)
def get_angle(self, point)
Definition: circle.py:23
def __init__(self, center, radius)
Definition: circle.py:12
def fit(points)
Definition: circle.py:36
Point
Definition: circle.py:8
def get_closest_point(self, point)
Definition: circle.py:26
def create_array(self, start_angle, end_angle, sample_count=50)
Definition: circle.py:16