This is more of a gee-whiz answer than a practical one, because if all you are doing is intersecting two lines it is very slow. However I thought it was worth a mention.
WPF has the ability to intersect any two shape outlines, including two lines, and tell you the location of the intersection.
Here is the general technique for intersecting two outlines (the edges, not the fill area):
var shape1 = ...;
var shape2 = ...;
var thinPen = new Pen(Brush.Transparent, 0.001);
var geometry1 = shape1.RenderedGeometry.GetWidenedPathGeometry(thinPen);
var geometry2 = shape2.RenderedGeometry.GetWidenedPathGeometry(thinPen);
var combined = Geometry.Combine(
geometry1,
geometry2,
GeometryCombineMode.Intersect,
shape2.TransformToVisual(shape1));
var bounds = combined.GetRenderBounds(thinPen);
If the shapes are known to have the same position the shape2.TransformToVisual(shape1)
in the call to Geometry.Combine
can be replaced with null
.
This technique can be very useful, if, for example, you need to intersect a line with an arbitrary curve.