I am trying to calculate the orthocenter of this triangle with vertices v1 = (42.9269, -307.8938), v2 = (-3816.060, 5723.502), v3 = (1766.106, 1973.672). My math seems to be correct, but the altitudes of the triangle do not appear to be perpendicular to the sides of the triangle.
The algorithm:
- Find the slope $(dv_1v_2)$ for line between vertices $v_1$ and $v_2$
- Find the slope $(dv_1v_3)$ for line between vertices $v_1$ and $v_3$
- Calculates the negative reciprocal of both $dv_1v_2$ and $dv_1v_3$ as these should be the slopes of the triangle altitudes $(m_{alt})$
- Calculate $y$-Intercepts of both triangle altitudes from vertice 2 and 3: $I_{alt2}, I_{alt3}$
- Find the intersection of these altitudes
Given the equations for the altitude lines:
$$
y = m_{alt2}\cdot x + I_{alt2} \\
y = m_{alt3}\cdot x + I_{alt3}
$$
Where $I_{alt}$ is the intercept of the altitude line given by:
$$
I_{alt3} = v_{3y} - m_{alt3} \cdot v_{3x}\\
I_{alt2} = v_{2y} - m_{alt2} \cdot v_{2x}
$$
And $m_{alt}$ is the slope of the altitude line . Then the equation for the intersection of these two altitude lines is: $$ \begin{bmatrix} - m_{alt3} & 1 \\ - m_{alt2} & 1 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} I_{alt3} \\ I_{alt2} \end{bmatrix} $$
I wrote a code to compute it in R:
v1 <- c(42.9269, -307.8938)
v2 <- c(-3816.060, 5723.502)
v3 <- (1766.106, 1973.672)
dv1v2 <- (v2[2] - v1[2]) / (v2[1] - v1[1])
dv1v3 <- (v3[2] - v1[2]) / (v3[1] - v1[1])
dv3B <- -1 / dv1v2
dv2A <- -1 / dv1v3
interceptV3B <- v3[2] - dv3B * v3[1]
interceptV2A <- v2[2] - dv2A * v2[1]
A <- matrix(c(-dv3B, 1, -dv2A, 1), byrow = TRUE, nrow = 2)
B <- matrix(c(interceptV3B, interceptV2A), byrow = TRUE, nrow = 2)
orthocenter <- solve(A) %*% B
For the given points, my results for the orthocenter are (1431.956 1759.878). An online calculator verified the results.
Here is an image I plotted, followed by an image from an online calculator that matches.
My results (yellow is orthocenter):
Online calculator results match mine (red is orthocenter):
None of these altitudes look perpendicular to me!
This is what I expect an altitude to look like, every altitude is 90 degrees in this image:

I verified that the altitude and side between vertices is perpendicular with the formula: $angle = atan(abs((slope1-slope2)/(1+slope1*slope2)))$. This shows that the angle is $\frac{pi}{2}$, yet none of the altitudes look 90 degrees, so I don't believe it.
Why don't these altitude lines look 90 degrees to their opposite sides? Looking at the image, I would think the orthocenter would be closer to $x = 0$
Orthocenter calculator for reference: https://www.mathportal.org/calculators/analytic-geometry/triangle-calculator.php


Correct drawing:
Correct drawing, angle at $v_3$ is about $86^o$