Skip to content Skip to sidebar Skip to footer

Draw Circle With Sin and Cos

  1. #ane

    iflash is offline

    Thread Starter

    Hyperactive Member


    Draw a circle with cos() and sin()

    Howdy,

    I don't want to use any api or avant-garde stuff. Can someone pls tell me how to draw a circle with the functions cos() and sin()? I've seen someone exercise information technology but can't rememver how. IT's like lines of the aforementioned length pointing out from the centre with fifty-fifty spaces in betwixt each line, more lines there are, the more than smoothen the edge of the circle will be.

    thnx in accelerate, it's s'pose to be somethin elementary....


  2. #2

    Information technology would exist far easier and faster to just use the Shape command, with its shape belongings set to circle

  3. #three

    iflash is offline

    Thread Starter

    Hyperactive Member


    Yes, simply can y'all pls prove me how to draw a circle manually by using cos(), sin() and the line role?

    thnx i'll really capeesh information technology.


  4. #4

    Hmmm okay I'll try.
    Give me a few minutes ...

  5. #five

    You don't happen to have any formulae for working with circles do y'all ?

    eg. is a point on a circumvolve etc ?


  6. #6

    iflash is offline

    Thread Starter

    Hyperactive Member


    i know the sine = o / h, cos = a / h, tan = a / h

    but i desire to use LINE to depict circles. Pls help.


  7. #seven

    Bearing in heed that I've forgotten all my trig, this is the all-time I could come upward with.

    It works a treat, except for one minor thing.
    The pixel organisation on computers is and so modest that the equations don't really work a lot of the fourth dimension, so you have to permit for some fault, thus the reason I added in the precision thing.
    The college the number, the greater the range for error, and the lower the number, the more precise you want information technology

    VB Code:

                                  
    1. Individual Sub Form_Load()

    2.     Picture1.AutoRedraw = True

    3.     Show

    4.     drawCircle 50, 50, 50, Picture1

    5. End Sub

    6. Private Sub drawCircle(centreX As Long, centreY As Long, r Every bit Long, destPBox As PictureBox)

    7.     Dim x Equally Long, y As Long

    8.     destPBox.ScaleMode = 3

    9.     For x = 0 To destPBox.ScaleWidth

    10.         For y = 0 To destPBox.ScaleHeight

    11.             If isPointOnCircle(ten, y, centreX, centreY, r, 50) Then destPBox.PSet (x, y), vbRed

    12.         Adjacent

    13.     Next

    14. End Sub

    15. Private Role isPointOnCircle(x As Long, y As Long, centreX As Long, centreY Equally Long, r As Long, precision As Long) As Boolean

    16.     isPointOnCircle = (((x - centreX) * (x - centreX)) + ((y - centreY) * (y - centreY)) = r * r) Or _

    17.                         ((((x - centreX) * (x - centreX)) + ((y - centreY) * (y - centreY)) <= (r * r) + precision) And _

    18.                         (((10 - centreX) * (x - centreX)) + ((y - centreY) * (y - centreY)) >= (r * r) - precision))

    19. End Function


  8. #viii

    iflash is offline

    Thread Starter

    Hyperactive Member


    thnx

    But the code i've seen before lookz somethin like the post-obit:

    Lawmaking:

    For i = i to 50    X = 'some cos function times something    Y = 'some sin role times something    'utilise the line office to draw from centre of circle to new point side by side i

  9. #9

    Okay.
    The way information technology would work is every bit follow.

    You kickoff at the centrepoint, and draw a line out of length r (r = radius of circle).
    Then y'all observe the co-ordinates of the point at the end of a line drawn at an angle � up from that line, and draw a line from the previous end of line to the new finish of line.
    Incriment �, and echo until the new end of line is the same terminate of line equally the line you first drew.

    But I retrieve that would be quite deadening ...


  10. #x

    Does this help?

    Code:

    Dim ten Every bit Unmarried Dim y As Unmarried Dim a As Integer Dim r Every bit Integer Dim xoff Every bit Integer Dim yoff Every bit Integer          ' R is the radius of the circumvolve     r = 1000          xoff = 1000 ' x center of circle     yoff = 1000 ' y center of circle          ' Step through the angle in steps of 1 degree     For a = 1 To 360         ten = Cos(a) * r         y = Sin(a) * r         Me.PSet (xoff + x, yoff + y)     Next

  11. #eleven

    Originally posted past darrenl
    Does this help?

    Code:

    Dim x As Unmarried Dim y As Single Dim a As Integer Dim r Every bit Integer Dim xoff As Integer Dim yoff Every bit Integer          ' R is the radius of the circle     r = 1000          xoff = yard ' x center of circle     yoff = 1000 ' y heart of circle          ' Step through the angle in steps of 1 degree     For a = 1 To 360         x = Cos(a) * r         y = Sin(a) * r         Me.PSet (xoff + 10, yoff + y)     Next

    Nice code. Does it a tad more than eloquently than I had suggested for the trigonometric arroyo.
    You'd want to stick in AutoRedraw = True before you start drawing though
    Last edited by plenderj; Feb 15th, 2002 at 07:20 AM.

  12. #12

    iflash is offline

    Thread Starter

    Hyperactive Member


    Tin you lot modify your code to apply the LINE office ? thnx a lot

  13. #13

    This example uses line to depict between points in a circle, a new varaible (pace) is used for the number of points in the circle.

    Had to modify the code because last version was inccorect. VB uses radians for COS and SIN calcs. To get passed this I have used a conversion variable (PI) that when multiplied against will catechumen degrees into radians.

    Code:

    Dim x As Single Dim y As Single Dim xpre As Single  ' Previous point to draw from Dim ypre Every bit Single  ' Previous point to describe from Dim a As Integer Dim r As Integer Dim xoff Equally Integer Dim yoff As Integer Dim step Equally Single Dim pi As Single     ' just for plender    Me.AutoRedraw = True    Me.Cls        ' Rough PI calc     pi = (22 / 7) / 180          ' Step is the in degrees, this is the resolution of your circle     step = 360 / 20 ' 20 point circle     '  an interesting effect is when you divide by say 3, you volition draw a triangle     ' divide by 4 and yous will get a square!          ' R is the radius of the circle     r = m          xoff = g ' x center of circle     yoff = g ' y middle of circle          ' Step through the angle in steps of 1 degree     For a = 1 To 360 Footstep stride         10 = Cos(a * pi) * r         y = Sin(a * pi) * r         xpre = Cos((a - step) * pi) * r         ypre = Sin((a - step) * pi) * r         Me.Line (xoff + xpre, yoff + ypre)-(xoff + 10, yoff + y)     Next     Me.AutoRedraw = Imitation
    Last edited by darrenl; Feb 15th, 2002 at 07:43 AM.

    Dazzer


Posting Permissions

  • You may not post new threads
  • Yous may not post replies
  • You may not postal service attachments
  • You may not edit your posts
  • BB code is On
  • Smilies are On
  • [IMG] code is On
  • [VIDEO] code is On
  • HTML lawmaking is Off

Click Here to Expand Forum to Total Width

zehrregrarm.blogspot.com

Source: https://www.vbforums.com/showthread.php?143757-Draw-a-circle-with-cos()-and-sin()

Post a Comment for "Draw Circle With Sin and Cos"