From 4e1c8f9a965f2d85e4c3b53b176cb2dfda34c681 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Tue, 11 Jun 2024 09:25:38 +0100 Subject: [PATCH] Add the denominator to curvature checks --- beziers/cubicbezier.py | 2 +- beziers/quadraticbezier.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/beziers/cubicbezier.py b/beziers/cubicbezier.py index f973c4a..4eed4c2 100644 --- a/beziers/cubicbezier.py +++ b/beziers/cubicbezier.py @@ -209,7 +209,7 @@ def curvatureAtTime(self, t: float) -> float: return ( d.pointAtTime(t).x * d2.pointAtTime(t).y - d.pointAtTime(t).y * d2.pointAtTime(t).x - ) + ) / ((d.pointAtTime(t).x ** 2 + d.pointAtTime(t).y ** 2) ** 1.5) @property def tunniPoint(self) -> Point: diff --git a/beziers/quadraticbezier.py b/beziers/quadraticbezier.py index ad6ba2c..0a40ec3 100644 --- a/beziers/quadraticbezier.py +++ b/beziers/quadraticbezier.py @@ -112,6 +112,14 @@ def findExtremes(self): """Returns a list of time `t` values for extremes of the curve.""" return self._findDRoots() + def curvatureAtTime(self, t: float) -> float: + """Returns the C curvature at time `t`.""" + d = self.derivative() + d2 = self.end - self.start # A constant + return (d.pointAtTime(t).x * d2.y - d.pointAtTime(t).y * d2.x) / ( + (d.pointAtTime(t).x ** 2 + d.pointAtTime(t).y ** 2) ** 1.5 + ) + @property def area(self): """Returns the signed area between the curve and the y-axis"""