-
- VBForums
- Visual Basic
- Visual Basic 6 and Earlier
- Draw a circle with cos() and sin()
-
February 15th, 2002,05:19 AM #ane 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.... -
Feb 15th, 2002,05:23 AM #2 Information technology would exist far easier and faster to just use the Shape command, with its shape belongings set to circle -
Feb 15th, 2002,05:25 AM #three 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. -
Feb 15th, 2002,05:26 AM #4 Hmmm okay I'll try. Give me a few minutes ... -
Feb 15th, 2002,05:42 AM #five You don't happen to have any formulae for working with circles do y'all ? eg. is a point on a circumvolve etc ? -
Feb 15th, 2002,05:46 AM #6 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. -
Feb 15th, 2002,06:01 AM #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: -
Individual Sub Form_Load() -
Picture1.AutoRedraw = True -
Show -
drawCircle 50, 50, 50, Picture1 -
End Sub -
Private Sub drawCircle(centreX As Long, centreY As Long, r Every bit Long, destPBox As PictureBox) -
Dim x Equally Long, y As Long -
destPBox.ScaleMode = 3 -
For x = 0 To destPBox.ScaleWidth -
For y = 0 To destPBox.ScaleHeight -
If isPointOnCircle(ten, y, centreX, centreY, r, 50) Then destPBox.PSet (x, y), vbRed -
Adjacent -
Next -
End Sub -
Private Role isPointOnCircle(x As Long, y As Long, centreX As Long, centreY Equally Long, r As Long, precision As Long) As Boolean -
isPointOnCircle = (((x - centreX) * (x - centreX)) + ((y - centreY) * (y - centreY)) = r * r) Or _ -
((((x - centreX) * (x - centreX)) + ((y - centreY) * (y - centreY)) <= (r * r) + precision) And _ -
(((10 - centreX) * (x - centreX)) + ((y - centreY) * (y - centreY)) >= (r * r) - precision)) -
End Function -
February 15th, 2002,06:35 AM #viii 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 -
Feb 15th, 2002,06:40 AM #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 ... -
Feb 15th, 2002,07:00 AM #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 -
Feb 15th, 2002,07:04 AM #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. -
Feb 15th, 2002,07:18 AM #12 Thread Starter Hyperactive Member Tin you lot modify your code to apply the LINE office ? thnx a lot -
February 15th, 2002,07:35 AM #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 -
- VBForums
- Visual Basic
- Visual Basic vi and Earlier
- Draw a circle with cos() and sin()
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
Forum Rules | Click Here to Expand Forum to Total Width |
Post a Comment for "Draw Circle With Sin and Cos"