I have the starting and end coordinates and equation of an inclined line. I want to discretize it into elements of length 1mm. Then check in which range of elements a particular point lies.
The equation is in point-normal form: 6.16x - 9.23y -9.31 = 0.
The x and y coefficients are the components of the normal vector to the line.
My solution was:
To find the angle the line makes with the horizontal, using the formula for dot product since we know the components of the normal vector to the line.
Calculate the step size for the x and y coordinates considering the element size to be 1mm. like this.
Take the point I want to check for and see which range it lies in.
Is there a better way to do this?
Yes.
Let $P_0$ be your given "starting point".
Find the "direction vector" of the line. Let $\mathbf{v}$ be the vector pointing from the starting point to the ending point (obtained by subtracting coordinates).
Convert $\mathbf{v}$ to a unit vector. First, compute the length $h = \sqrt{9.23^2 + 6.16^2}$, and let $$ \mathbf{u} = \frac{1}{h} \mathbf{v}. $$
Assuming that all the units here are in mm to begin with, you can, starting from $P_0$, construct the point $$ P_i = P_0 + i \mathbf{u}. $$ These points will lie along the line, separated by $1mm$. Use values $i$ from $0$ to $h$. if $h$ is not an integer, you will want to round up to the next higher integer.