Drawing ovals, calculating circumference, recording x,y co-ords of along the circumference

Posted on 2005-04-16
Last Modified: 2008-02-26
I need to be able to generate an oval on a VB form that appears on a slant.  By slant I mean...  The oval will always be taller than it is wide and the top will always be on the left side of the form when compared to the bottom.  Therefore, giving the oval the appearance of being positioned at a 135 degree angle roughly on the screen.

The second part of this is that I need to be able to calculate the circumference of the oval generated so I can make calculations on placing labels around the oval with equal spacing between them.  

The last piece of this is that I need to be able to say that if I want to place a label X number of pixels (unit of measurement is irrelevant and will be determined by the second part of this question) from the top of the oval then the X and Y co-ords for the label will be...

Thanks in advance!  I've been strugggling with this for a while.
Question by:Xawble
    LVL 37

    Accepted Solution

    Hi Xawble,

    Try this... (This will draw an Oval of Major Axis 8000, Mino Axis 5000 and angle 135 Deg). This code is specially written for you !!
    If you have any doubts, please ask

    Private Sub Form_Click()
        Const M_PI = 3.14159265358
        Let incl = 135
        Let mj = 8000
        Let mn = 5000
        Dim x, y, ang As Double
        For ang = 0 To 360 Step 0.05
            x = mj * Cos(ang * M_PI / 180) * Cos(incl * M_PI / 180) - mn * Sin(ang * M_PI / 180) * Sin(incl * M_PI / 180)
            y = -mn * Sin(ang * M_PI / 180) * Cos(incl * M_PI / 180) - mj * Cos(ang * M_PI / 180) * Sin(incl * M_PI / 180)
            PSet (Me.Width / 2 + x, Me.Height / 2 + y)
    End Sub

    LVL 37

    Expert Comment

    by:Harisha M G
    If the oval is too large, make mj = 4000 and mn = 2000

    Author Comment

    That's exactly what I am looking for!  I'll just need to play with the numbers a bit to get the proper size and position.  Any idea on how to figure out the circumference of that and space labels out around the circumference?
    LVL 37

    Expert Comment

    by:Harisha M G
    Well... it depends on the size of the labels you are going to use...

    Note that Me.Width/2 & Me.Height/2 specify the centre of the form... and
    mj is the major axis, mn is the minor axis.

    The height and width of the oval depends naturally on the values of mj & mn.
    And the inclination angle is given by incl.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
    Article by: Martin
    Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now