title: C# offset a point perpendicular to a given line segment
body: <p>I have a line segment defined by two PointD (a custom type to work with doubles rather than floats, as the Math in C# works in doubles): p1 (.541, 41.929), p2 (363.736, 88.48) - assume that the line will be sloped. </p>
  
  <p>At unpredictable intervals, I need to set an offset point perpendicular to the segment a variable distance- lets just say, 0.125, 0.25, etc.. </p>
  
  <p>It seems all the example out there assume that you'll always need this perpendicular point to be based on the mid point.</p>
  
  <p>I have solved for p3 by: (</p>
  
  <pre><code>private PointD subPt(PointD a, PointD b, double p)
      {
          double x = (1 - p) * a.X + p * b.X;
          double y = (1 - p) * a.Y + p * b.Y;
  
          return new PointD(x, y);
      }
  </code></pre>
  
  <p>The return point for 0.25 is (91.339, 53.566). I have validated this in cad to be accurate enough for my requirements.</p>
  
  <p>The thing I cannot figure out for the life of me, is how to then get a perpendicular point 5 (just to make it round) away from the line.</p>
  
  <p>The results I am expecting are p4 (90.705, 58.526)</p>