Jump to content


Photo

Sizing down drawing?


3 replies to this topic

#1 WarrenW

WarrenW

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 10 January 2006 - 06:46 PM

In my VB6 program I have outlined some text in a picturebox and have generated a list of coordinates for lines. These x/y coordinates are in pixels based on the size of the font. I then create a new DXF file and add these lines to save. When I display the DXF file I have created the text is far too big because the units are for inches. It seems one pixel is equal to one inch. How can I scale down the size of the drawing? The only thing I have tried so far is dividing each coordinate by a number to make each one smaller. That works but I have to divide by around 50 to get the sizing right and then the text gets messed up it seems.

Any auggestions? If I can get this right, I will register your control immediately.

Thanks!

Warren

#2 Athanasios Gardos

Athanasios Gardos

    Administrator

  • Admin
  • 360 posts
  • Gender:Male

Posted 23 January 2006 - 07:25 AM

To scale the coordinates you can use the following VB6 source code:

Private Sub Form_Load()
    Dim sclx As Single, scly As Single
    Dim px As Single, py As Single
    Dim x() As Single, y() As Single
    Dim i As Long, MaxPoints As Long
    MaxPoints = 2
    ReDim x(MaxPoints) As Single, y(MaxPoints) As Single
    x(1) = 10
    y(1) = 10
    x(2) = 1000
    y(2) = 1000
    ReDim mat2d(3, 3) As Single
    sclx = 1 / 50
    scly = 1 / 50
    px = 0
    py = 0
    Call ScaleMatrix(sclx, scly, px, py, mat2d()) 'Make scale matrix from point px,py
    For i = 1 To MaxPoints
        Call TransformXY(x(i), y(i), mat2d()) 'Transform points
    Next i
End Sub

Public Function ScaleMatrix(sclx As Single, scly As Single, px As Single, py As Single, mat2d() As Single) As Boolean
    Call MATidn(mat2d())
    mat2d(1, 1) = sclx
    mat2d(2, 2) = scly
    mat2d(3, 1) = px * (1 - sclx)
    mat2d(3, 2) = py * (1 - scly)
    mat2d(3, 3) = 1
    Scale2dMat = True
End Function

Public Sub MATidn(a() As Single)
    Dim g1 As Long
    Dim s1 As Long
    Dim i As Long
    Dim j As Long
    g1 = UBound(a, 1)
    s1 = UBound(a, 2)
    For i = 1 To g1
        For j = 1 To s1
            If i = j Then a(i, j) = 1 Else a(i, j) = 0
        Next j
    Next i
End Sub

Public Function MATmul(a() As Single, b() As Single, Reslt() As Single) As Boolean
    Dim g1 As Single
    Dim g2 As Single
    Dim s1 As Single
    Dim s2 As Single
    Dim i As Long
    Dim j As Long
    Dim k As Long
    g1 = UBound(a, 1)
    s1 = UBound(a, 2)
    g2 = UBound(b, 1)
    s2 = UBound(b, 2)
    If s1 <> g2 Then Exit Function
    ReDim Reslt(g1, s2) As Single
    For i = 1 To g1
        For j = 1 To s2
            For k = 1 To s1
                Reslt(i, j) = Reslt(i, j) + a(i, k) * b(k, j)
            Next k
        Next j
    Next i
    MATmul = True
End Function

Public Function TransformXY(x As Single, y As Single, mat2() As Single) As Boolean
    Dim Reslt() As Single
    ReDim tr(1, 3) As Single
    tr(1, 1) = x
    tr(1, 2) = y
    tr(1, 3) = 1
    If MATmul(tr(), mat2(), Reslt()) = True Then
       x = Reslt(1, 1)
       y = Reslt(1, 2)
       TransformXY = True
    End If
End Function

Athanasios Gardos
Avax-Software.com

#3 WarrenW

WarrenW

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 24 January 2006 - 05:01 AM

Thanks for the code. Can you tell me how to use this? And how do I set how far it scales down the size? If I can understand this I will register the control tomorrow. How do I pass in each x/y coordinate to scale down?

Thanks!

Warren

#4 DarrylChe

DarrylChe

    Newbie

  • Banned
  • Pip
  • 1 posts

Posted 02 February 2011 - 04:18 PM

you just need to change the values of x and y in the above code.


p90x | fat burning furnace

Edited by DarrylChe, 16 February 2011 - 07:16 PM.




Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users