Is there a formula for drawing a line between two points, without extending past them? (Explained Below)

86 Views Asked by At

I'm trying to make something in a 2D graphing calculator: A 3D Object which can be moved about, i've already got the vertices/points done, but i need something to draw lines between them.

This is where i'm stuck: I can't use $m={(y_2-y_1)\over (x_2-x_1)}$ Because what if the X coordinates (in 2D) Are the same?
Example: Point A is at (5,10) and Point B is at (5,-10)
If we use the above formula, we subtract the y coordinates:
$m={(-10-10)\over (x_2-x_1)}$
Which equals
$m={-20\over (x_2-x_1)}$
Then we subtract the X coordinates:
$m={-20\over 5-5}$
Which equals
$m={-20\over 0}$
Which equals $m=Undefined$

This requires division by zero, But if we somehow found the value of $-20 \over 0$, then the formula for the line would be $(y-y_1)=m(x-x_1)$
Which if we fill in for:
$(y-10)=\frac{-20}{0} (x-5)$
The actual answer is that the formula is $x=5$

But we can't just say that the line is $x=A_1$ or $x=B_1$, because their X coordinates could also differ, like with $A=(10,10)$ and $B=(5,5)$ Where the equation is $y=x$

You can format any way you like and stuff, as a function ($\operatorname{f}(x)$) As an equation ($y=\dots$) or even as a polynomial ($ax+by+c=0$)

Oh and with the 2 different solutions above (which work for their individual cases) they extend past the points which wouldn't be that useful for displaying a 3D Object as a line just connecting the 2.

And as a tip, the equation i used for projecting 2D onto 3D was $x_{Projected}= {d \over z} x$ Where $x_{Projected}$ is the 2D location of x, $z$ is the Z coordinate of the point, and $d$ is the distance between the "Camera" and the XY plane - replacing $x_{Projected}$ with $y_{Projected}$ and $x$ with $y$ Results in $y_{Projected}$ being the y coordinate of the point in 2D.

1

There are 1 best solutions below

0
On BEST ANSWER

As shown in the comment above, the formula is $r=A+t(B−A)$

Thanks to @Paul for the answer (although @Paul should of posted as a answer, not a comment)