Results 1 to 2 of 2

Thread: anti aliasing a bresenham line

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    8

    anti aliasing a bresenham line

    Hi,

    I am trying to anti-alias a bresenham line. I have this code so far. My only problem is that for the two variables that are declared as double, i have some problems. When i get to the code:

    invD = 1.0 / (2.0 * Sqr(du * du + dv * dv))
    invD2du = 2.0 * (du * invD)

    It becomes

    invD = 1# / (2# * Sqr(du * du + dv * dv))
    invD2du = 2# * (du * invD)

    There are # signs instead of decimals. Then i get overflow errors. Does anyone know how to fix this, or if there is a better way to anti alias the bresenham line? This would help me tremendously. Thankyou.



    Code:
       dim uend As Integer
        Dim uincr As Integer
        Dim vincr As Integer
        Dim addr As Integer
        Dim incrS As Integer
        Dim incrD As Integer
        Dim twovdu As Integer
        
       Dim invD As Double
        Dim invD2du As Double
    
        Dim du As Integer
        Dim dv As Integer
        Dim u As Integer
        Dim v As Integer
        
        addr = (y0 * 640 + x0) * 4
        dx = x1 - x0
        dy = y1 - y0
        
        If Abs(dx) > Abs(dy) Then
        du = Abs(dx)
        dv = Abs(dy)
        u = x1
        v = y1
        uincr = 4
        vincr = 640 * 4
        If dx < 0 Then
            uincr = -uincr
        End If
            
        If dy < 0 Then
            vincr = -vincr
        End If
        
        Else
            
            du = Abs(dy)
            dv = Abs(dx)
            u = y1
            v = x1
            uincr = 640 * 4
            vincr = 4
            If dy < 0 Then
                uincr = -uincr
            End If
            
            If dx < 0 Then
                vincr = -vincr
            End If
        End If
        
        uend = u + 2 * du
        d = (2 * dv) - du
        incrS = 2 * dv
        incrD = 2 * (dv - du)
        twovdu = 0
        invD = 1.0 / (2.0 * Sqr(du * du + dv * dv))
        invD2du = 2.0 * (du * invD)
        
        Do
        
            PSet (addr, twovdu * invD)
            PSet (addr + vincr, invD2du - twovdu * invD)
            PSet (addr - vincr, invD2du + twovdu * invD)
            
            If d < 0 Then
                twovdu = d + du
                d = d + incrS
            Else
                twovdu = d - du
                d = d + incrD
                v = v + 1
                addr = addr + vincr
            End If
            u = u + 1
            addr = addr + uincr
        Loop While (u < uend)

  2. #2
    Addicted Member
    Join Date
    Aug 2002
    Posts
    192
    the # means the computer is recognizing the number as a double. if you put 1.1, the # would disappear, however it is best to leave it because to my knowledge, any number without a type declaration following it is treated as a variant. 9! means single, 9# means double, 4& means Long, 4% means integer. The # most likely PREVENTS overflow, so the problem is that your calculations are going way over.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width