dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: VB4,VB5,VB6
Expertise: Intermediate
Oct 20, 2001

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


DrawPolygon - Draw a closed polygon with any number of sides

' Draw a polygon, given its center and number of sides
' CTRL can be either a form or a PictureBox control.
' ANGLE is an optional angle in degrees

Sub DrawPolygon(ctrl As Object, ByVal xc As Single, ByVal yc As Single, _
    ByVal side As Single, ByVal numSides As Integer, _
    Optional ByVal angle As Single)
    Dim deltaAngle As Single
    Dim r As Single
    Dim i As Integer
    Dim x2 As Single
    Dim y2 As Single
    
    ' evaluate the angle formed by each side (in radians)
    deltaAngle = 3.14159265358979 * 2 / numSides
    ' evaluate the radius of the circle that wraps the polygon.
    r = side / Sin(deltaAngle / 2)
    ' convert the initial angle in radians
    angle = angle / 57.2957795130824
    
    ' Draw individual sides
    For i = 1 To numSides
        ctrl.Line (xc + r * Sin(angle), yc + r * Cos(angle))-(xc + r * Sin _
            (angle + deltaAngle), yc + r * Cos(angle + deltaAngle))
        angle = angle + deltaAngle
    Next

End Sub

Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date