public static LineF FindPerpendicular(PointF p, LineF l) { //return LineF.FromSlope(p, -l.Slope, 50); float yi = LineF.FindYIntercept(p, (-(l.PointB.X - l.PointA.X)) / (l.PointB.Y - l.PointA.Y)).Y; return(new LineF(p, new PointF(p.X + 20, ((p.X + 20) * ((-(l.PointB.X - l.PointA.X)) / (l.PointB.Y - l.PointA.Y))) + yi))); }
//*************************************************************************** // Static Methods // /// <summary>Creates a line segment from the given point and slope, using the given x offset as the location of the other end of the segment.</summary> /// <param name="p">The coordinate of the start of the segment.</param> /// <param name="m">The slope of the line.</param> /// <param name="x">The x-coordinate of the end of the segment. The y-coordinate will be calculated using y=mx.</param> /// <returns>A <see cref="T:AllOneSystem.Drawing.LineF"/> value of the new line segment.</returns> public static LineF FromSlope(PointF p, float m, float x) { //LineF nl = new LineF(new PointF(p.X, 0), new PointF(p.X + 10, m * (p.X + 10))); float yi = LineF.FindYIntercept(p, m).Y; return(new LineF(p, new PointF(p.X + x, (m * (p.X + 10)) + yi))); }
/// <summary>Determines the coordinate of intersection of two lines. If the given line segments do not actually intersect, this will return the point where they would intersect on an infinite plane.</summary> /// <param name="val1">An initialized <see cref="T:RainstormStudios.Drawing.LineF"/> value representing the first line.</param> /// <param name="val2">An initialized <see cref="T:RainstormStudios.Drawing.LineF"/> value representing the second line.</param> /// <returns></returns> public static PointF FindIntersect(LineF val1, LineF val2) { // First, we need the y-intercepts for each line. float yi1 = LineF.FindYIntercept(val1).Y; float yi2 = LineF.FindYIntercept(val2).Y; // Now that we have the slope and y-intercept of each line, the equations // to find the intercept are easy. double ix = ((-yi1) + yi2) / (val1.Slope - val2.Slope); double iy = (((-val1.Slope) * yi2) + (val2.Slope * yi1)) / (val1.Slope - val2.Slope); // And then, we just return our new point, but inverting the y-coordinate, // due to the method used to determine the y-intercept of our lines. return(new PointF((float)ix, (float)(-iy))); }