I'm writing a program to help calculate the incenter of a triangle given its vertices. There are 2 ways to do this: Finding the intersections of angle bisectors, and finding where the distance to the sides are equal.

I don't know how to do the second, but I came up with a way to do the first.

I convert 2 slopes to angles, average them, and convert it back to a slope with tan( and its inverse.

The problem comes with a special case where one of the slopes of a line that is a side of the triangle is vertical. I cannot calculate it because of the div by 0 error.

So I need another way to calculate the incenter. It could be by somehow finding the point that is equidistant to the sides, or another way to calculate angle bisectors.

Help?

Incenter