The error happens here:
tri2 = (180 - tri1) / 2;
At this point, you treat tri1
as degrees, before the conversion. If you want to subtract an angle from the value of the "straight" 180° angle, use π instead of 180, the measure of the straight angle in radians:
tri2 = (Math.PI - tri1) / 2;
This call is also incorrect
triDegree = Math.toDegrees(tri2);
marking2 = off3 / Math.tan(triDegree);
because triDegree
is expressed in degrees, while tan
is expecting a value expressed in radians.