VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Draws a line from XStart, YStart at the angle passed in Degrees. LineLen is the length, and LineCol

by Dennis Neal (1 Submission)
Category: Math/Dates
Compatability: Visual Basic 4.0 (32-bit)
Difficulty: Unknown Difficulty
Originally Published: Tue 3rd July 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Draws a line from XStart, YStart at the angle passed in Degrees. LineLen is the length, and LineColor is the color of the line in QBColor

Rate Draws a line from XStart, YStart at the angle passed in Degrees. LineLen is the length, and LineCol



    YStart As Integer, LineLen As Integer, LineColor As Byte)

' Draws a line from XStart, YStart at the angle passed in Degrees.
' LineLen is the length, and LineColor is the color of the line
' in QBColor values from 0 to 15.
' This assumes that zero degrees is up from the center, and
' increasing numbers are in a clockwise direction.

    Dim LineXEnd As Integer
    Dim LineYEnd As Integer
    Dim Radians As Single
    Dim PI As Single
    PI = 3.141592654

    Do Until Degrees < 360
        Degrees = Degrees - 360
    Loop
    
    Select Case Degrees
    Case 0
        LineXEnd = XStart
        LineYEnd = YStart - LineLen
    Case Is > 0 And Degrees < 90
        Radians = Degrees * (PI / 180)
        LineXEnd = XStart + (Sin(Radians) * LineLen)
        LineYEnd = YStart - (Cos(Radians) * LineLen)
    Case 90
        LineXEnd = XStart + LineLen
        LineYEnd = YStart
    Case Is > 90 And Degrees < 180
        Radians = Degrees * (PI / 180)
        LineXEnd = XStart + (Sin(Radians) * LineLen)
        LineYEnd = YStart - (Cos(Radians) * LineLen)
    Case 180
        LineXEnd = XStart
        LineYEnd = YStart + LineLen
    Case Is > 180 And Degrees < 270
        Radians = Degrees * (PI / 180)
        LineXEnd = XStart + (Sin(Radians) * LineLen)
        LineYEnd = YStart - (Cos(Radians) * LineLen)
    Case 270
        Radians = Degrees * (PI / 180)
        LineXEnd = XStart + (Sin(Radians) * LineLen)
        LineYEnd = YStart - (Cos(Radians) * LineLen)
    Case Else
        Radians = Degrees * (PI / 180)
        LineXEnd = XStart + (Sin(Radians) * LineLen)
        LineYEnd = YStart - (Cos(Radians) * LineLen)
    End Select
    
    Me.Line (XStart, YStart)-(LineXEnd, LineYEnd), QBColor(LineColor)

End Sub


Download this snippet    Add to My Saved Code

Draws a line from XStart, YStart at the angle passed in Degrees. LineLen is the length, and LineCol Comments

No comments have been posted about Draws a line from XStart, YStart at the angle passed in Degrees. LineLen is the length, and LineCol. Why not be the first to post a comment about Draws a line from XStart, YStart at the angle passed in Degrees. LineLen is the length, and LineCol.

Post your comment

Subject:
Message:
0/1000 characters