New feature! Upgrade and increase expert visibility of your issues with Priority Questions.
e.SmoothingMode = SmoothingMode.HighQuality;
float Cx = this.posx;
float Cy = this.posy;
float Fx = this.finalx;
float Fy = this.finaly;
float Vx = Cx;
float Inc;
Inc=1;
float a = (Cy - Fy) / (Cx - Fx);
float b = (Cx * Fy - Fx * Cy) / (Cx - Fx);
if (Cx > Fx) Inc = -1;
while(Vx != Fx)
{
///////by Interpolation y=ax+b
///////where a=(y1-y2)/(x1-x2)
//////b =(x1*y2-x2*y1)/(x1-x2)
Vy = a * Vx + b;
e.DrawRectangle(Pens.Red, Vx, Vy, 4, 4);
Vx = Vx + Inc;
}
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
ALGO 1
lineplot(x1,y1,x2,y2)
{
for x=x1 to x2
{
y = f(x)
setPixel(x,y)
}
}
ALGO 2
lineplot(x1,y1,x2,y2)
{
// verify which is bigger: |x2-x1| or |y2-y1|
if |x2-x1| > |y2-y1|
then loop x values from x1 to x2
else loop y values from y1 to y2
}
PSEUDOCODE 1
lineplot(x1,y1,x2,y2)
{
if abs(x2-x1) > abs(y2-y1)
then // loop by varying x values
{
dx = abs(x2-x1) / (x2-x1) // will be +1 or -1
// calculate line equation
m = (y2-y1) / (x2-x1) // if x2=x1 then the line is vertical
c = y1 - m*x1
for x=x1 to x2 step dx
{
y = m*x + c
setPixel(x,y)
}
}
else
{
// do the equivalent by varying y values
}
}
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.