Results 1 to 8 of 8

Thread: What an angle

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    12

    What an angle

    Hello everyone, I am a custom kitchen cabinet maker by trade and visual basic
    is a new found hobby of mine. I am trying to write a program to draw simple floor
    plans to help me with my kitchen layouts.
    Well I'm off to a great start!
    I can't draw a rectangle on an angle. However, I can draw a rectangle using
    using the top and left property of the shape control. But that don't tilt.
    Could someone show me the code to draw a rectangle that tilts on
    a angle. A constant of 4 could represent the wall thickness.
    I would like to be able to draw the rectangle with the line control and then
    transfer those x,y to use the line method in a picture box at any angle that I want
    using the mouse.
    I would like to use a label to show the angle in degrees ( 0 - 360 ) that the
    rectangle is being drawn.
    I know how to use the line method to draw one line ( or side ) on an angle,
    but I don’t know the formula to draw the other three sides and keep
    all the corners square.
    I would like to thank everyone who has taken the time to look at this
    this, and especially grateful to anyone who can help with the code.

    Here is what I have:

    Form name = Form1
    StartUpPosition = Manual
    ScaleMode = 1
    Width = 7980
    Height = 7560

    Picture box name = Picture1
    Appearance = 1-3D
    BackColor = White
    AutoRedraw = True
    MousePointer = 2-Cross
    Hieght = 5535
    Left = 120
    Top = 120
    Width = 7215
    ScaleMode = 3-Pixel

    Line control named = Line1 ‘ Used for rubber banding effect
    BorderColor = Red
    Visable = False
    X1 = 120
    X2 = 224
    Y1 = 312
    Y2 = 312

    '*******************************************
    Declarations

    Dim a As Long
    Dim b As Long
    Dim c As Long
    Dim d As Long

    Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

    a = X
    b = Y
    c = X
    d = Y

    Line1.X1 = a
    Line1.Y1 = b
    Line1.X2 = c
    Line1.Y2 = d
    Line1.Visible = True

    End Sub

    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    c = X
    d = Y
    Line1.X2 = c
    Line1.Y2 = d

    'Label1.Caption = "Some sort of code to show the angle of the rectangle" & "Degrees"

    End Sub

    Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

    Dim e As Long
    Dim f As Long
    Dim g As Long
    Dim h As Long

    e = Line1.X1
    f = Line1.Y1
    g = Line1.X2
    h = Line1.Y2

    Picture1.Line (e, f)-(g, h), RGB(50, 75, 255)

    Line1.X1 = 0
    Line1.Y1 = 0
    Line1.X2 = 0
    Line1.Y2 = 0
    Line1.Visible = False
    Picture1.Visible = False
    Picture1.Visible = True

    '*************************************************
    'All this extra code will draw a square on any angle, but not the rectangle
    'that I want to use
    Dim X1 As Long
    Dim X2 As Long
    Dim Y1 As Long
    Dim Y2 As Long
    Dim SlopeT As Long 'Top part of slope fraction
    Dim SlopeB As Long 'Bottom part of slope fraction

    SlopeT = (h - f) * 1
    SlopeB = (g - e) * -1
    X1 = e + SlopeT
    Y1 = f + SlopeB
    Picture1.Line (e + SlopeT, f + SlopeB)-(e, f), RGB(50, 75, 255)

    'the other side
    SlopeT = (f - h) * -1
    SlopeB = (e - g) * 1
    X2 = g + SlopeT
    Y2 = h + SlopeB
    Picture1.Line (g + SlopeT, h + SlopeB)-(g, h), RGB(50, 75, 255)

    'And the last line
    Picture1.Line (X1, Y1)-(X2, Y2), RGB(50, 75, 255)
    End Sub

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Well to draw a rotated rectangle, I'd just use 4 lines joined together. To rotate the rectangle, just rotate the positions of the 4 points all together ...
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    12

    Smile What angle

    Is this code understandable? Am I not explaining the description well enough?
    Has anyone tried the code? I have scratched my head so much over this angle thing that I soon may need stitches.

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Once you have gotten the top, left, bottom, and right properties, you can use a simple rotation algorithm when you have the top-left, top-right, bottom-left, and bottom-right. I can attach a simple draw - a - rectange, select rotation program.

    Give me a few minutes!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  5. #5
    Zaei
    Guest
    Well, if you know how to draw one line at an angle, its very easy to draw the other 3 lines as well. You have a regular rectange, with all right angles, correct? If you can draw the bottom line at an angle, the right side will extend up at (angle + 90), the top will just be another bottom, but starting at the endpoint of the right side, and the left side will just join the endpoints of the top and bottom. to speed things up, you can just draw the top and bottom lines, then connect the enpoints of those lines to form the rectangle.

    Z.

  6. #6
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Well my VB crashed, so I wont be able to get that example to you, my suggestion is to use Zaei's advice.

    ONLY 5 MORE POSTS!!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  7. #7

    Thread Starter
    New Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    12

    Unhappy What angle

    Thank you all for the replies
    Zaei if you have the time try the code and run the so called
    program. It will draw a square at any angle you wish by useing
    the mouse curser. I wan't to use a Constant number such as 8
    for the rectangle height and still keep the sides at a 90 degree angle to the first line. I just cant get the cords of the third
    corner ( second lines X2, Y2 ). I know that the X1, Y1
    of the second line will be the same as the X1,Y1 of the first line.
    If I new how to get the second line I THINK I can figure out the other two lines.
    Thanks to all that have seen this.

  8. #8
    Zaei
    Guest
    Use the method i gave you. If you are rotating the rectangle by 45 degrees, say, you would get the bottom line by rotating it by 45 degrees. Get the second line the same way, except using 45 + 90 as the rotation factor.

    Z.

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