Finding the right angle from revit

I’ve been making a graph so others could more easily draw an “edge” (I’m not sure how to properly translate it). I’ve been using sastrugi and a line based family so I could create these. I didn’t just use a line based family because the angle between the two instances matters, and I wanted to let it calculate it to make it easier to place. It works generally alright, with the exception of cases where it adds 90 degrees. This had been a problem earlier but I managed to fix it when I realized it always occured when the angle would turn over the y axis. so I added a bit of code in the graph to avoid that.

Currently however, this is happening:

As you can see, it doesn’t draw the angles consistently, it only seems to happen when the edges are drawn alongside the x-axis or y-axis.

This is my graph:

Does anyone have an idea what might be going wrong here?

Does anyone know?