In a fit of laziness I've used Fit
to fit lines to the point sets in cornerpoints
, where we are after the line gradients. The issue here is that Fit
finds the y values in terms of the x values, and thus isn't appropriate for us where one x has multiple y images. There are various workarounds, but it would be better to just use a more suitable algorithm.
Take each set of points, and calculate the differences between successive points in each dimension. Then total these differences, and divide them to obtain the average gradient along each line. Plug these gradients into some trigonometry for the angle between the two lines.
ListPlot[#, PlotLabel ->
N[Abs[-180 / Pi ArcTan[(x - y)/(1 + x y) /. {
x -> Divide @@ Total[Differences[#[[1]]]],
y -> Divide @@ Total[Differences[#[[2]]]]
}]], AspectRatio -> 1, PlotRange -> All] & /@ cornerpoints
This leads to a lot of division by zero complications (that I have not resolved in the above implementation), and makes the fitted lines harder to plot over the data; but most importantly, is always correct!