Is there an equation that will graph a line segment?

Around a year or so ago I came up with an equation that, when graphed on a real graph, graphs a line segment. It does so by making the numbers which are not a part of the segment imaginary, thus unable to be graphed on a real graph. The equation is as follows: $$y=\frac{(B-D)\left(\sqrt{x-A}\sqrt{|x-A|}-\sqrt{C-x}\sqrt{|C-x|}-x\right)+AB-CD}{A-C}$$ where (A,B) is the left-most point and (C,D) is the right-most point (that is, where $C > A$.) $$y \in \begin{cases} \ \mathbb{R} & \iff A \le x \le C,\\ \ \mathbb{I} & \text{otherwise} \end{cases}$$ So, in English, $y$ will be real if and only if $x$ is between $A$ and $C$; otherwise, it will be imaginary. Say for example I wanted to graph a segment from (-4,3) to (5,6). In that case, the equation becomes $$y=\frac{(3-6)\left(\sqrt{x+4}\sqrt{|x+4|}-\sqrt{5-x}\sqrt{|5-x|}-x\right)-(-4\bullet3)-(5\bullet6)}{-4-6}$$ which results in the following: $$\text{when}\; x=-5,\; y=3+\frac{1}{3}i;\; x=-4,\; y=3;\; x=5,\; y=6;\; x=6,\; y=6-\frac{1}{3}i$$ I have no clue for what, if anything, this could be used. I just thought I would share it since it was doing me no good. Anyway, thank you in advance for any positive feedback or constructive criticism.


Thinking in another way from the answer from Steven Fontaine, you can use any function that is only defined for some $x\in\Bbb R$ but not other $x$'s.

For example, since $\arcsin x$ is only defined for $[-1,1]$, you can write

$$y = mx + c + \arcsin x - \arcsin x$$

to "capture" the piece of straight line between $[-1,1]$. By adjusting the domain of $\arcsin (m'x+c')$ using $m'$ and $c'$, you can then "capture" any non-vertical finite segment.

Similarly, you may use $\sqrt{x}$ or $\ln{x}$ to graph a ray, the former includes the starting point and the latter does not.


Or you can just use vectors. $(x,y,z)+t\langle a,b,c\rangle$.

That is to say, for a line going from point $(1,1,1)$ to the point $(21,21,21)$, the equation would be $r(t)=(1,1,1)+t\langle 1,1,1\rangle$ such that $0<t<21$