#### bacteriaman

##### Member

I have a tricky math problem that has me stumped.

I need to gradually draw a line one pixel at a time between two points. I know the start and end X/Y coordinate values and the current incremented X value. Using these values, I need to calculate each y-axis to gradually draw a line from the start X/Y to the current X until reaching end X/Y.

For example, suppose we have a 100x100 grid with a start X/Y of 0/0 and end X/Y of 100/100. I also have an incremented X counter that progresses from left to right. That said, the line will not be perfectly straight or diagonal so the y-axis will not be predictable.

The following link illustrates the above:

www.mathportal.org/calculators/analytic-geometry/two-point-form-calculator.php?val1=0&val2=0&val3=100&val4=100&rb1=slop&ch1=expl

The page includes a formula, but I am uncertain how to implement it to calculate the Y dynamically.

Or perhaps there's a different or better approach. Any comments/suggestions is much appreciated.

I need to gradually draw a line one pixel at a time between two points. I know the start and end X/Y coordinate values and the current incremented X value. Using these values, I need to calculate each y-axis to gradually draw a line from the start X/Y to the current X until reaching end X/Y.

For example, suppose we have a 100x100 grid with a start X/Y of 0/0 and end X/Y of 100/100. I also have an incremented X counter that progresses from left to right. That said, the line will not be perfectly straight or diagonal so the y-axis will not be predictable.

The following link illustrates the above:

www.mathportal.org/calculators/analytic-geometry/two-point-form-calculator.php?val1=0&val2=0&val3=100&val4=100&rb1=slop&ch1=expl

The page includes a formula, but I am uncertain how to implement it to calculate the Y dynamically.

Or perhaps there's a different or better approach. Any comments/suggestions is much appreciated.

Last edited: