Open srichakradhar opened 1 year ago
same error
it worked when I deleted the '@abstractmethod' from lines 43, 46, 49 and 52 from segment.py
在geometry文件夹中增加一个LineSegment.py文件(LineSegment名称可以任意修改),代码为: import numpy as np from .segment import Segment
class LineSegment(Segment): def init(self, points): super().init(points)
if len(points) != 2:
raise ValueError("LineSegment requires exactly two points: start and end.")
self.start = np.array(points[0])
self.end = np.array(points[1])
self.delta = self.end - self.start
def compute_x(self, t):
return self.start[0] + t * self.delta[0]
def compute_y(self, t):
return self.start[1] + t * self.delta[1]
def compute_dx(self, t):
# 对 t 的一阶导数为 delta 的 x 分量,因为对于直线来说,这个值不变
return self.delta[0]
def compute_dy(self, t):
# 对 t 的一阶导数为 delta 的 y 分量,因为对于直线来说,这个值不变
return self.delta[1]
然后在simulation.py中将from .geometry.segment import Segment修改为from .geometry.LineSegment import LineSegment as Segment
Environment
Python version: Python3 Operating System: MacOS
Issue
Since abstract classes cannot be instantiated, and require subclasses to provide implementations for the abstract methods, the
Segment
should stop extending fromABC
and the abstract methods need to be removed.