Drawing Oval!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • parkho
    New Member
    • Feb 2008
    • 6

    Drawing Oval!

    hi, I have a form which I want to draw 4 Ovals with the same center point but with different directions so it looks like a star. I used the circle command which I can only get two Ovals on the desired direction and I cannot get the other two in right position. Please help me!
    Thanks
  • douglandmesser
    New Member
    • Feb 2008
    • 10

    #2
    The best way to do what you want is to use SIN/COS functions. You can adjust the circle to do pretty much whatever you want. Give it a try. You will need to assign a value to PI. Also, use a FOR...NEXT loop for the actual 360 points on the circles. I have some code, but it's written in QB. You should be able to convert it to VB code quite easily. Let me know if you want it.

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Originally posted by douglandmesser
      The best way to do what you want is to use SIN/COS functions. You can adjust the circle to do pretty much whatever you want. Give it a try. You will need to assign a value to PI. Also, use a FOR...NEXT loop for the actual 360 points on the circles. I have some code, but it's written in QB. You should be able to convert it to VB code quite easily. Let me know if you want it.
      Actually, surprisingly enough you don't need to use Pi at all in drawing a circle. You just vary the X and Y coordinates that you draw based on Sin() and Cos() of a value. For example...

      [CODE=vb]
      Dim S As Single
      For S = 0 to 6 Step 0.1
      Me.Pset (50+Sin(S)*25, 50+Cos(S)*25)
      Next
      [/CODE]
      Sorry if this code isn't quite right, I don't have time to test it. Just typed it straight in here. Anyway, to produce an oval shape, you just change the ratio of what you add to the X and Y coordinates (Eg. add 25 to X and 10 to Y). To slant the oval, I guess you'd need to make a further variation.

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        Please find a related article here .

        Comment

        • parkho
          New Member
          • Feb 2008
          • 6

          #5
          Originally posted by douglandmesser
          The best way to do what you want is to use SIN/COS functions. You can adjust the circle to do pretty much whatever you want. Give it a try. You will need to assign a value to PI. Also, use a FOR...NEXT loop for the actual 360 points on the circles. I have some code, but it's written in QB. You should be able to convert it to VB code quite easily. Let me know if you want it.
          hi, thanks for the reply. Is it possible for you to post the code so I can some Idea? thanks so much.

          Comment

          • debasisdas
            Recognized Expert Expert
            • Dec 2006
            • 8119

            #6
            Have you gone through the article provided in the link.

            Comment

            • parkho
              New Member
              • Feb 2008
              • 6

              #7
              Originally posted by debasisdas
              Have you gone through the article provided in the link.
              yes I have. It gives me the basics of the Circle command which I already knew. my problem is that I want all the Ovals with the same center point NOT with different Center points. that looks like a star just like we turn them around at one center point.

              Thanks

              Comment

              • debasisdas
                Recognized Expert Expert
                • Dec 2006
                • 8119

                #8
                Then what are you expecting the complete code ?

                Comment

                • Killer42
                  Recognized Expert Expert
                  • Oct 2006
                  • 8429

                  #9
                  I think there's one important question that we don't have a definite answer to as yet. You can produce interesting effects quite simply, by varying the aspect ratio of the circle (look up "circle" in the VB doco). That is, by making it taller or wider, so you get an oval shape. But that only makes horizontal/vertical ovals. Do you need tham at other angles as well?

                  Comment

                  • Killer42
                    Recognized Expert Expert
                    • Oct 2006
                    • 8429

                    #10
                    If anyone's interested, here is some code where I was playing around with doing different offsets from the centre of the circle, depending on which "quarter" you're in. It's not terribly useful, but may inspire some ideas.

                    It uses a routine I wrote years ago for an analogue clock display, which takes a minute from 0 to 59 and converts it to the appropriate value to produce a point on the circle using Sin and Cos. that's why the code uses numbers from 0 to 59.

                    [CODE=vb]Private Sub Form_Click()
                    Dim S As Integer, Q As Double
                    Dim OffsetX As Single, OffsetY As Single
                    For S = 0 To 59
                    Q = Converted(S)
                    Select Case S
                    Case 0 To 14
                    OffsetX = (Abs(7 - Abs(7.5 - S))) * 5
                    OffsetY = (Abs(7 - Abs(7.5 - S))) * 5
                    ' Case 15 To 29
                    ' OffsetX = (Abs(7 - Abs(22.5 - S))) * 5
                    ' OffsetY = (Abs(7 - Abs(22.5 - S))) * 5
                    Case 30 To 44
                    OffsetX = (Abs(7 - Abs(37.5 - S))) * 5
                    OffsetY = (Abs(7 - Abs(37.5 - S))) * 5
                    ' Case 45 To 59
                    ' OffsetX = (Abs(7 - Abs(52.5 - S))) * 5
                    ' OffsetY = (Abs(7 - Abs(52.5 - S))) * 5
                    Case Else
                    OffsetX = 0
                    OffsetY = 0
                    End Select

                    If S = 0 Then
                    Me.PSet (150 + Sin(Q) * (50 + OffsetX), 100 + Cos(Q) * (50 + OffsetY))
                    Else
                    Me.Line -(150 + Sin(Q) * (50 + OffsetX), 100 + Cos(Q) * (50 + OffsetY))
                    End If
                    Next

                    End Sub

                    Private Function Converted(What As Integer) As Double

                    ' Note:
                    ' Step size = .105 (roughly)
                    ' Starting at 0 points us at 6 on the clock.
                    ' Therefore, about 3.15 should put us at 12 o'clock..

                    Converted = (58 - What) * 0.1067 + 3.15

                    End Function
                    [/CODE]If anyone plans to try it, the other point of note is that I set the form's ScaleMode to "3 - Pixel".

                    Comment

                    Working...