JM
Research Projects
Maths
Solution
for a line intersecting a line segment
Figure
1
Given
a line segment (x1,y1), (x2,y2), and a third line with angle g3,
will the third line intersect the line segment, and if so calculate the
intersect point (x3,y3) and the distance d of the intersect point
(x3,y3) from the origin.
If
the point (x1,y1) has angle g1 and the point (x2,y2) has the angle
g2, then the line with angle g3 will intersect line segment
(x1,y),(x2,y2) if g1 > g3 > g2.
The
problem is useful to solve in computer graphics and 2D modelling to
work out whether line segments are cut by a line.
If
there are many line segments, then if g1 > g3 > g2 relation is
not satified by a particular line segment, then that line segment can
be dropped from further calculations.
If
there are many line segments that are cut by one line, then
selecting the smallest distace d also select the line segment that is
closest to the origin when cut.
This
type of problem is usually solved in text books by
calculating the gradients and working out the intersect point.
That
method however is prone to numerical blow up when gradients become
infinite.
The
solution described here uses the sine law and algebra with a big
helping hand from xmaxima to get final answer:
sin(g3) x1 y2 - sin(g3) x2 y1
[y3 = -------------------------------------------------]
cos(g3) y2 - cos(g3) y1 - sin(g3) x2 + sin(g3) x1
cos(g3) x1 y2 - cos(g3) x2 y1
[x3 = -------------------------------------------------]
cos(g3) y2 - cos(g3) y1 - sin(g3) x2 + sin(g3) x1
x2 y1 - y2 x1
[d = -------------------------------------------------]
sin(g3) x2 - cos(g3) y2 - sin(g3) x1 + cos(g3) y1
Example
dxf CAD file to check formula - intersection_worked_example.dxf
Contact
A
limited range of work involving formulae, maths
and computer algorithms undertaken.
The results can be supplied as formulae and/or C code with test data.
Please contact describing the problem in its entirety and what you need
in terms of results.
If the work is within our scope then you will be sent a quotation.
sales: research@enemygadgets.com
Copyright (C) J.
Michael 2010