dda算法_C和C ++中的DDA线图绘制算法
dda算法
Here you will learn about?dda line drawing algorithm in C and C++.
在這里,您將了解C和C ++中的dda線條繪制算法。
In Computer Graphics the first basic line drawing algorithm is Digital Differential Analyzer (DDA) Algorithm.
在計算機圖形學中,第一個基本的線條繪制算法是數字差分分析器(DDA)算法。
A line connects two points. It is a basic element in graphics. To draw a line, you need two points between which you can draw a line.
一條線連接兩個點。 它是圖形中的基本元素。 要繪制一條線,您需要兩個點之間可以繪制一條線。
Also Read:?Bresenham’s Line Drawing Algorithm in C and C++
另請參閱: Bresenham的C和C ++線條畫算法
數字差分分析儀(DDA)算法 (Digital Differential Analyzer (DDA) Algorithm)
Step 1:?Read the input of the 2 end points of the line as (x1, y1) & (x2, y2) such that x1 != x2 and y1 != y2
步驟1:將線的兩個端點的輸入讀取為(x1,y1)&(x2,y2),以使x1!= x2和y1!= y2
Step 2:?Calculate dx = x2 – x1 and dy = y2 – y1
步驟2:計算dx = x2 – x1和dy = y2 – y1
Step 3:
第三步:
if(dx>=dy)
如果(dx> = dy)
step=dx
步長= dx
else
其他
step=dy
步長= dy
Step 4:?xin = dx / step & yin = dy / step
步驟4: xin = dx / step和yin = dy / step
Step 5:?x = x1 + 0.5 & y = y1 + 0.5
步驟5: x = x1 + 0.5&y = y1 + 0.5
Step 6:?
步驟6:
for(k = 0; k < step; k++)
for(k = 0; k <步驟; k ++)
{
{
x = x + xin
x = x +鑫
y = y + yin
y = y + yin
putpixel(x, y)
putpixel(x,y)
}
}
C語言中的DDA線圖繪制算法程序 (Program for?DDA Line Drawing Algorithm in C)
#include <graphics.h> #include <stdio.h> #include <math.h> #include <dos.h>void main( ) {float x,y,x1,y1,x2,y2,dx,dy,step;int i,gd=DETECT,gm;initgraph(&gd,&gm,"c:\\turboc3\\bgi");printf("Enter the value of x1 and y1 : ");scanf("%f%f",&x1,&y1);printf("Enter the value of x2 and y2: ");scanf("%f%f",&x2,&y2);dx=abs(x2-x1);dy=abs(y2-y1);if(dx>=dy)step=dx;elsestep=dy;dx=dx/step;dy=dy/step;x=x1;y=y1;i=1;while(i<=step){putpixel(x,y,5);x=x+dx;y=y+dy;i=i+1;delay(100);}closegraph(); }Outptut
輸出
C ++中DDA線條繪制算法程序 (Program for DDA Line Drawing Algorithm in C++)
#include <graphics.h> #include <iostream.h> #include <math.h> #include <dos.h>void main( ) {float x,y,x1,y1,x2,y2,dx,dy,step;int i,gd=DETECT,gm;initgraph(&gd,&gm,"c:\\turboc3\\bgi");cout<<"Enter the value of x1 and y1 : ";cin>>x1>>y1;cout<<"Enter the value of x2 and y2: ";cin>>x2>>y2;dx=abs(x2-x1);dy=abs(y2-y1);if(dx>=dy)step=dx;elsestep=dy;dx=dx/step;dy=dy/step;x=x1;y=y1;i=1;while(i<=step){putpixel(x,y,5);x=x+dx;y=y+dy;i=i+1;delay(100);}closegraph(); }Comment below if you have any doubts related above algorithm.
如果您對以上算法有任何疑問,請在下面評論。
翻譯自: https://www.thecrazyprogrammer.com/2017/01/dda-line-drawing-algorithm-c-c.html
dda算法
總結
以上是生活随笔為你收集整理的dda算法_C和C ++中的DDA线图绘制算法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 用DDA算法绘制一条直线
- 下一篇: Xv6 编译运行