Results 1 to 11 of 11

Thread: [RESOLVED] Dividing a circle

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2012
    Location
    UK
    Posts
    20

    Resolved [RESOLVED] Dividing a circle

    Hi there!
    I’m having big trouble trying to design some stimuli for a visual experiment. Mainly because programming (and maths) is not my strong point, plus I’m not even sure if VB can do what I need…

    Anyways, I’ve managed to draw a centred circle with specific parameters and a fixation point in the middle, but what I now need is to divide it into 6 equal parts by passing a line through each equally spaced point and the centre. While I know how to do that with a protractor on a piece of paper, I have no clue how to do it in code And it pains me to think this is just the simplest manipulation I need to do in order to draw this stimulus. I’m trying to take it one step at a time and figure out as much as I can on my own, but unfortunately time is against me . I’d appreciate any help, suggestions, advice… Thank you all!

    PS: I’m using VB 6.0 and only have basic beginner knowledge.

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Jan 2012
    Location
    UK
    Posts
    20

    Resolved Re: Dividing a circle

    Ha! It took me a while, but I brushed up on my trigonometry and I figured it out myself (with little help from Google of course ). I consider this resolved now

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2012
    Location
    UK
    Posts
    20

    Re: Dividing a circle

    Rrrright... I spoke too soon. I don't mean to be annoying, but I have another problem now. I've created most of the stimuli as I wanted, but there seems to be something wrong. I've uploaded a picture in combination to the code. The small circles within the 'doughnut' shape should be equally spaced from each other and should be centred on the outline of the green circle. However, as it appears obvious from the image - this is not the case. The bottom and top two are not centred where they should be. Also, they are not really equally spaced
    Is there something wrong with the code? Am I overlooking something really obvious
    My code:
    Private Sub Form_Paint()
    Const pi As Double = 3.142
    'draw the circle on which the stimuli will be centred
    Me.Circle (Me.ScaleWidth / 2, Me.ScaleHeight / 2), 5.74, vbGreen

    'find points on the circle at specified radians
    '(6 equally spaced locations)
    'and centre a small circle at each point
    Dim x, y As Integer
    x = (Cos(2 * pi) * 5.74) + Me.ScaleWidth / 2
    y = (Sin(2 * pi) * 5.74) + Me.ScaleHeight / 2
    Form1.Circle (x, y), 0.64, vbGreen
    Dim x2, y2 As Integer
    x2 = (Cos(pi / 3) * 5.74) + Me.ScaleWidth / 2
    y2 = (Sin(pi / 3) * 5.74) + Me.ScaleHeight / 2
    Form1.Circle (x2, y2), 0.64, vbRed
    Dim x3, y3 As Integer
    x3 = (Cos(5 * pi / 3) * 5.74) + Me.ScaleWidth / 2
    y3 = (Sin(5 * pi / 3) * 5.74) + Me.ScaleHeight / 2
    Form1.Circle (x3, y3), 0.64, vbBlue
    Dim x4, y4 As Integer
    x4 = (Cos(4 * pi / 3) * 5.74) + Me.ScaleWidth / 2
    y4 = (Sin(4 * pi / 3) * 5.74) + Me.ScaleHeight / 2
    Form1.Circle (x4, y4), 0.64, vbYellow
    Dim x5, y5, x6, y6 As Integer
    x5 = (Cos(pi) * 5.74) + Me.ScaleWidth / 2
    y5 = (Sin(pi) * 5.74) + Me.ScaleHeight / 2
    Form1.Circle (x5, y5), 0.64, vbCyan
    x6 = (Cos(2 * pi / 3) * 5.74) + Me.ScaleWidth / 2
    y6 = (Sin(2 * pi / 3) * 5.74) + Me.ScaleHeight / 2
    Form1.Circle (x6, y6), 0.64, vbMagenta

    'Draw a point at the centre of each circle
    Me.DrawWidth = 3
    Me.PSet (Me.ScaleWidth / 2, Me.ScaleHeight / 2)
    Me.PSet (x2, y2)
    Me.PSet (x5, y5)
    Me.PSet (x6, y6)
    Me.PSet (x, y)
    Me.PSet (x3, y3)
    Me.PSet (x4, y4)
    End Sub

    The result:
    Name:  circle.JPG
Views: 710
Size:  24.3 KB

    PS: The scale is set to centimetres.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jan 2012
    Location
    UK
    Posts
    20

    Re: [RESOLVED] Dividing a circle

    Ok, here I am some time later to continue my potentially annoying monologue... I realised my mistake is in declaring variables as Integers when clearly they are NOT whole numbers... duh! When I switch to Double it all works fine

    I'm really sorry and kind of ashamed , I promise next time I'll give it at least 24 hours before I post something :P

  5. #5
    Fanatic Member ThomasJohnsen's Avatar
    Join Date
    Jul 2010
    Location
    Denmark
    Posts
    528

    Re: [RESOLVED] Dividing a circle

    If you don't want to bother with the trig-functions, the coordinates for the regular unit-hexagon with center (0, 0) are:
    { (1, 0), (0.5, sqrt(3/4)), (-0.5, sqrt(3/4)), (-1, 0), (-0.5, -sqrt(3/4)), (0.5, -sqrt(3/4)) }
    In truth, a mature man who uses hair-oil, unless medicinally , that man has probably got a quoggy spot in him somewhere. As a general rule, he can't amount to much in his totality. (Melville: Moby Dick)

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jan 2012
    Location
    UK
    Posts
    20

    Re: [RESOLVED] Dividing a circle

    Ah, yes! That would be quite helpful because although I've managed to centre the circles, they're still not equally spaced
    However... I'm not sure how to draw a hexagon... I mean, what kind of argument do you use to input these coordinates? I'd be great if there was a Me.Hexagon option, but I sense it's bound to be more to it and I don't seem to be able to figure it out

    Oh! And of course, thank you very much for the suggestion!

  7. #7
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: [RESOLVED] Dividing a circle

    Quote Originally Posted by Pine_Apple View Post
    ......they're still not equally spaced
    As I see it, the coordinates you are using are correct, you are already using the same coordinates as Pine_Apple suggested, although you do compute them using Cos and Sin.
    Your point x;y uses Cos(2Pi) and Sin(2Pi) which are 1 and 0
    your point x1;y1 uses Cos(Pi/3) and Sin(Pi/3) which are 0.5 and Sqrt(3/4) or better 0.86666..
    etc...
    So, why do you think your points (which form a hexagon, although "you can't draw it") are not equally spaced?
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Jan 2012
    Location
    UK
    Posts
    20

    Re: [RESOLVED] Dividing a circle

    Quote Originally Posted by opus View Post
    So, why do you think your points (which form a hexagon, although "you can't draw it") are not equally spaced?
    Yeah... it makes no sense for them to not be spaced equally cause the coordinates are correct, I'm sure of that! However, they aren't! In the end I actually measured them manually by placing a protractor on the monitor (oh yes, I went there!) and it turned out the first angle was 62 instead of 60, and then next proportion was 58 So everything was off by approximately 2 degrees. No idea why... so I 'cheated' by centering the small circles at 59, 121, 239 and 301 degrees. This almost corrected for it. It seems fine now...

  9. #9
    Fanatic Member ThomasJohnsen's Avatar
    Join Date
    Jul 2010
    Location
    Denmark
    Posts
    528

    Re: [RESOLVED] Dividing a circle

    As I see it, the only place that the error can arise is due to your approximation of Pi with 3.142.
    Pi represented as a double is actually 3,14159265358979.
    In truth, a mature man who uses hair-oil, unless medicinally , that man has probably got a quoggy spot in him somewhere. As a general rule, he can't amount to much in his totality. (Melville: Moby Dick)

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Jan 2012
    Location
    UK
    Posts
    20

    Re: [RESOLVED] Dividing a circle

    Yeah, I thought so too! But it didn't make any difference There must be something fundamentally wrong with the scales because I also just noticed that the centimetre measurements are not accurate either... e.g. I set diameters of 1.28 and and 7.02, instead it generates them as 1.6 and 8.7 (approximately). Well... I don't think I can do anything about that but bite the bullet and somehow try to work around it

    Thanks for the help and tips!

    Edition: Oups.. I messed up those values a bit, that's not exactly how they turned out, but it doesn't matter cause the fact is that the centimetre measurements are not accurate.
    Last edited by Pine_Apple; Jan 11th, 2013 at 08:49 AM.

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Jan 2012
    Location
    UK
    Posts
    20

    Re: [RESOLVED] Dividing a circle

    Rrrright! As embarrassing as this is... I have finally realised what the issue is... The resolution of the screen!!! It's fixed now and everything corresponds to the correct measurements as it should have on the first place! What a relief!!

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