From 8914ab1ce44348a34c38be45f0328b0aea51bcaf Mon Sep 17 00:00:00 2001 From: kushal2000 <48222101+kushal2000@users.noreply.github.com> Date: Sun, 23 Jun 2019 21:13:32 +0530 Subject: [PATCH 1/3] Added nearest_point_on_line function to Line class --- utils/math_functions.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/utils/math_functions.py b/utils/math_functions.py index babd9ffc..edd415ad 100644 --- a/utils/math_functions.py +++ b/utils/math_functions.py @@ -166,7 +166,13 @@ def normalized_vector(self): # angle = math.atan(self.slope) angle = self.angle return Vector2D(math.cos(angle), math.sin(angle)) - + + def nearest_point_on_line(self,point): + t=((point.y-self.point.y)*self.angle+point.x-self.point.x)/(math.cos(self.angle)+math.sin(self.angle)*math.tan(self.angle)) + x1=self.point.x+math.cos(self.angle)*t + y1=self.point.y+math.sin(self.angle)*t + point=Vector2D(x1,y1) + return point ## ## @var slope From bda6911c0380762930759be8b621b2d81a41ca18 Mon Sep 17 00:00:00 2001 From: kushal2000 <48222101+kushal2000@users.noreply.github.com> Date: Sun, 23 Jun 2019 21:45:37 +0530 Subject: [PATCH 2/3] Correction made to nearest_point_on_line in Line class --- utils/math_functions.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utils/math_functions.py b/utils/math_functions.py index edd415ad..c8c20a46 100644 --- a/utils/math_functions.py +++ b/utils/math_functions.py @@ -168,7 +168,10 @@ def normalized_vector(self): return Vector2D(math.cos(angle), math.sin(angle)) def nearest_point_on_line(self,point): - t=((point.y-self.point.y)*self.angle+point.x-self.point.x)/(math.cos(self.angle)+math.sin(self.angle)*math.tan(self.angle)) + if math.cos(self.angle) == 0: + point = Vector2D(point.x,self.point.y) + return point + t=((point.y-self.point.y)*math.tan(self.angle)+point.x-self.point.x)*(math.cos(self.angle)) x1=self.point.x+math.cos(self.angle)*t y1=self.point.y+math.sin(self.angle)*t point=Vector2D(x1,y1) From bf0d1ca09e9668626a35a88da8e2f808e6a2d280 Mon Sep 17 00:00:00 2001 From: kushal2000 Date: Mon, 24 Jun 2019 02:23:17 +0530 Subject: [PATCH 3/3] Simplified formula --- utils/math_functions.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/utils/math_functions.py b/utils/math_functions.py index c8c20a46..8236ffc0 100644 --- a/utils/math_functions.py +++ b/utils/math_functions.py @@ -168,10 +168,7 @@ def normalized_vector(self): return Vector2D(math.cos(angle), math.sin(angle)) def nearest_point_on_line(self,point): - if math.cos(self.angle) == 0: - point = Vector2D(point.x,self.point.y) - return point - t=((point.y-self.point.y)*math.tan(self.angle)+point.x-self.point.x)*(math.cos(self.angle)) + t=(point.y-self.point.y)*math.sin(self.angle)+(point.x-self.point.x)*(math.cos(self.angle)) x1=self.point.x+math.cos(self.angle)*t y1=self.point.y+math.sin(self.angle)*t point=Vector2D(x1,y1)