If I have two 3d points on a graph how can I create an equation so that I can iterate down the line that intersects those two points?
Asked
Active
Viewed 373 times
0
-
What do you mean by "iterating down"? – Michael Hoppe Feb 04 '22 at 20:32
-
I mean setting up a loop and incrementing down that line getting a new position each time. I know how to do the looping I just need to know how to make an equation where I can get a new x, y, and z coordinate each time I move down the line at a fixed rate. – UnSure Feb 04 '22 at 20:41
-
Does this answer your question? Equation for a straight line in Cartesian space – David K Feb 05 '22 at 04:50
1 Answers
3
For points $\mathbf p$ and $\mathbf q$ you can represent all points on the connecting lines as $t\mathbf p + (1-t) \mathbf q$ where $t\in \mathbb R$. When $0\leq t \leq 1$ you get all the points on the line segment between $\mathbf p$ and $\mathbf q$.
BTW, this works for any $\mathbb R^n$, not just $\mathbb R^3$.
blamocur
- 1,153
-
Yes but how can I iterate down that line segment with only those 2 points? What system would you suggest me to use in order to create an equation that gives me a changing x, y, and z value as I move down that line segment at a constant rate? – UnSure Feb 04 '22 at 20:29
-
As said, iterate through the t values from 0 to 1 in whatever way you wish. If you want to ask a programming question you should add that tag. – Paul Feb 04 '22 at 21:11
-
@UnSure: if you change $t$ at a constant rate your point will move at a constant rate along the line. To find $x,y,z$ you convert the vector expression to 3 coordinate ones. For example, $x(t) = tp_x + (1-t)q_x$, where $p_x$ and $q_x$ are x-coordinates of $\mathbf p$ and $\mathbf q$ respectively. The same for $y$ and $z$. – blamocur Feb 04 '22 at 23:03