I have segment line with two points $T_1(x_1,y_1), T_2(x_2,y_2)$ and then I place the $3.$ point $T_3(x_3,y_3)$. Is there a way to check (with given $x_1, x_2, x_3, y_1, y_2, y_3)$ if perpendicular to the segment line $T_1,T_2$ from $T_3$ exists? I've managed to calculate the perpendicular for line but not the segment line. I am programming in C#.
double dx = x2 - x1;
double dy = y2 - y1;
double mag = Math.Sqrt(dx * dx + dy * dy);
dx /= mag;
dy /= mag;
double lambda = (dx * (x3 - x1)) + (dy * (y3 - y1));
rx1 = (dx * lambda) + x1;
ry1 = (dy * lambda) + y1;
rx1 and ry1 are coordinates of a point T3.
The equation of the line through $T_3$ that is perpendicular to the line through $T_1$ and $T_2$ is $$(x_2-x_1)(x-x_3)+(y_2-y_1)(y-y_3)=0.\tag{*}$$ The line segment $\overline{T_1T_2}$ does not intersect this line if the points $T_1$ and $T_2$ are on the same side of the line (*). This will occur when the values that you get by plugging in the coordinates of these points into the left-hand side of (*) have the same sign.
That is, compare the signs of $(T_1-T_3)\cdot(T_2-T_1)$ and $(T_2-T_3)\cdot(T_2-T_1)$: if they are both positive or both negative, then the projection of $T_3$ onto the line through $T_1$ and $T_2$ does not lie on the segment $\overline{T_1T_2}$. However, if you’re already computing the projection, anyway, a simple range check of its coordinates against those of $T_1$ and $T_2$ will also tell you whether or not the point lies on $\overline{T_1T_2}$.