Fitting as much points as possible on a line I want to fit a set of points on a 2D plane that looks like the blue points in the following picture. Instead of having a least square fit (the yellow, dotted line), I want a line that looks like the red line that either crosses the blue points as much as possible or is perpendicular to them. How can I achieve this?
I think as suggested in the comments, you should split this up in several linear regressions. 

If the datapoints are ordered you could just do repeated linear regressions, always adding one point until the added point leads to a significant reduced goodeness of fit. Then you start the next linear regression until that one goes bad and you start the next one. 
At the end you can compare the angles between the two lines and see if they are (roughly) 90 degrees.