0

So basically I have two problems which I need to solve for a whole bunch of times I have been using SymPy to solve each problem and while that works it simply runs to slow.

The first problem is I need to convert two line segments which I have the points for into lines and then find the intercept point of those lines. each line segment by itself does not intercept the other. I also need to find the angle between each of these lines in degrees. Below is the SymPy code that I am currently using with some example values while it works its to slow and I need to find another way to solve this that is significantly faster.

first problem:

import math
from sympy import Point, Line, Segment, Polygon

p1=Point(1, 4)
p2=Point(8, 8)

p3=Point(10, 10)
p4=Point(16, 16)

l1 = Line(p1, p2)
l2 = Line(p3, p4)

showIntersection = l1.intersection(l2)
unList=showIntersection[0]
points=unList.coordinates
angle = float(l1.angle_between(l2))
angleDegrees = angle*(180/math.pi)

x0inter=float(points[0])
y0inter=float(points[1])

the second problem is simpler I need to find if point('s) are enclosed inside a four sided polygon. I could use example code or advice on which library I should use.

  • Isn't a simple high school math problem (https://en.wikipedia.org/wiki/Linear_equation)?, you don't need to use Sympy. try to solve it manually and plug in the equations. you find the slopes, and substitute a point on line to get the equations. –  Oct 18 '21 at 09:06
  • [Selecting Points within a box](https://stackoverflow.com/questions/67391642/selecting-points-within-a-box-on-a-scatter-plot) contains a way to check whether points are inside a convex polygon. – JohanC Oct 18 '21 at 21:10
  • For line intersections, you can use sympy with points with variables as coordinates and let sympy generate the formula. Something like `l1 = Line(Point(x1,y1),Point(x2,y2))` etc.. For the angle, you could try `arccos` on the dot product of the normalized vectors. [Wikihow - angle between vectors](https://www.wikihow.com/Find-the-Angle-Between-Two-Vectors) – JohanC Oct 18 '21 at 21:19

0 Answers0