"bresenham's line algorithm c++" Code Answer's
You're definitely familiar with the best coding language C++ that developers use to develop their projects and they get all their queries like "bresenham's line algorithm c++" answered properly. Developers are finding an appropriate answer about bresenham's line algorithm c++ related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like bresenham's line algorithm c++. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on bresenham's line algorithm c++.
bresenham's line algorithm c++
void drawline(int x0, int y0, int x1, int y1)
{
int dx, dy, p, x, y;
dx=x1-x0;
dy=y1-y0;
x=x0;
y=y0;
p=2*dy-dx;
while(x<x1)
{
if(p>=0)
{
putpixel(x,y,7);
y=y+1;
p=p+2*dy-2*dx;
x+=1;
}
else
{
putpixel(x,y,7);
p=p+2*dy;}
x+=1;
}
}
bresenham line drawing algorithm code
#include<iostream.h>
#include<graphics.h>
void drawline(int x0, int y0, int x1, int y1)
{
int dx, dy, p, x, y;
dx=x1-x0;
dy=y1-y0;
x=x0;
y=y0;
p=2*dy-dx;
while(x<x1)
{
if(p>=0)
{
putpixel(x,y,7);
y=y+1;
p=p+2*dy-2*dx;
}
else
{
putpixel(x,y,7);
p=p+2*dy;
}
x=x+1;
}
}
int main()
{
int gdriver=DETECT, gmode, error, x0, y0, x1, y1;
initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");
cout<<"Enter co-ordinates of first point: ";
cin>>x0>>y0;
cout<<"Enter co-ordinates of second point: ";
cin>>x1>>y1;
drawline(x0, y0, x1, y1);
return 0;
}
Source: www.thecrazyprogrammer.com
Bresenham's line algorithm
static void bresenham(int x1, int y1, int x2, int y2)
{
int m_new = 2 * (y2 - y1);
int slope_error_new = m_new - (x2 - x1);
for (int x = x1, y = y1; x <= x2; x++)
{
System.out.print("(" +x + "," + y + ")\n");
// Add slope to increment angle formed
slope_error_new += m_new;
// Slope error reached limit, time to
// increment y and update slope error.
if (slope_error_new >= 0)
{
y++;
slope_error_new -= 2 * (x2 - x1);
}
}
}
All those coders who are working on the C++ based application and are stuck on bresenham's line algorithm c++ can get a collection of related answers to their query. Programmers need to enter their query on bresenham's line algorithm c++ related to C++ code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about bresenham's line algorithm c++ for the programmers working on C++ code while coding their module. Coders are also allowed to rectify already present answers of bresenham's line algorithm c++ while working on the C++ language code. Developers can add up suggestions if they deem fit any other answer relating to "bresenham's line algorithm c++". Visit this developer's friendly online web community, CodeProZone, and get your queries like bresenham's line algorithm c++ resolved professionally and stay updated to the latest C++ updates.