简体   繁体   中英

Determine if segment is between two lines

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.

平行线

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM