Determine if segment is between two lines

140 views Asked by At

I need to find out, if segment n is on the same side of the point F with segment XY.

All lines and segments are parallel, and length of the segments are same. In the illustration red segment AB is on the left side (of the line that strikes through point F). Blue segment CD is right (out)side given criteria.

How do you determine these two case in GeoGebra or Python?

Special case when segment is on F or E lines should be considered too. I hope this was enough for problem description.

Parallel lines

1

There are 1 answers

1
Gribouillis On

Here is how you could do it

u = (y[1]-y[0], x[0]-x[1])
delta = f[0] * u[0] + f[1] * u[1]
if delta < x[0]*u[0]+x[1]*u[1]:
    delta = -delta
    u = (-u[0], -u[1])
assert a[0] * u[0] + a[1] * u[1] < delta
assert b[0] * u[0] + b[1] * u[1] < delta
assert c[0] * u[0] + c[1] * u[1] > delta
assert d[0] * u[0] + d[1] * u[1] > delta

explanation: vector u is orthogonal to XY. The points that have a given scalar product with u form a line parallel to XY. For F this scalar product is delta. By optionally changing the sign of u, one can have delta greater for F than for X. Now the points which scalar product with u is greater than delta are on a parallel line that is farther from XY than the point F

Edit: sorry for the bugfix