计算机图形学填充算法代码_计算机图形学-DDA&BLA算法

Let us understand how DDA Algorithm works by taking some examples and solving them too. Just keep in mind two things one, Y=mx+b is the line equation. Second, If m is less than one increase X and calculate Y. If m is more than 1 then increase Y and calculate X. DDA Algorithm is explained by taking some examples.

Draw a line from (1,1) to (8,7) using DDA and BLA algorithms.

DDA- Digital Differential Analyser

This case is for slope (m) less than 1. Slope (m) =(7-1)/(8-1) = 6/7 .

S-1: x1=1; y1=1; x2=8; y2=7.

S-2: m=(7-1)/(8-1) = 6/7 which is less than 1.

S-3: As m (6/7) is less than 1 therefore x is increased and y is calculated.

S-4 : The step will be x1=x1+1 and y1= y1+6/7

007fe2c5a650c200546d5dd51c143adb.png

The algorithm will stop here as the x value has reached 7 though y has not reached 9. This is the limitation of this algorithm.

—————————————————————–

Lets take another example.

Draw a line using DDA Algorithm from (0,0) to (4,6)

This case is for slope (m) greater than 1. Slope (m) =(6-0)/(4-0) = 6/4 .

S-1: x1=0; y1=0; x2=4; y2=6

S-2: m=(6-0)/(4-0) = 6/4 which is more than 1.

S-3: As m (6/4) is greater than 1 therefore y is increased and x is calculated.

S-4 : But first we will calculate b (remember the equation of line : y=mx+b), so b = y1-m*x1; There fore b = 0 – 6/4*0 = 0. Which means that b =0.

S-4 : Now increase the value of y and calculate value of x.

  • To calculate x, take line equation and find x , which would be x=(y-b)/m
  • We will start from x1 =0, y1=0 , b =0 and m = 6/4
  • The step will be y1=y1+1 and x1= (y1-0)/(6/4), After simplifying , x1= (y1)*4/6

bc3d6080aae05db0837301db78618a81.png

The algorithm will stop here because the Y and X values have reached the End point (4,6).

Now let’s solve the same numerical using BLA Algorithm.

S-1: x1=1; y1=1; x2=8; y2=7.

S-2: dy=7-1 = 6 and dx = 8-1 = 7

dy-dx = 6-7 = -1; and 2 * dy = 12;

S-3: d=2*6 – 7 = 5;

S-4: we will increase x by 1 every step as m is less than 1 and calculate y as follows

  1. If d >=0 then x1 = x1 + 1 and y1 = y1 + 1 with new d = d + 2*(dy-dx)
  2. If d<0 then x1 = x1 + 1 and y1 will not change with new d = d + 2*d

dcb9d3adb0b6ff6ff405f82463fd9fa6.png

That's all.

Thanks for ur watching!!!!!!

Zhengzhi

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值