Announcement

Collapse
No announcement yet.

Graphic Ellipse

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Graphic Ellipse

    I have a use for Graphic Ellipse, but unfortunately (to my limited knowledge of graphics) the "GRAPHIC ELLIPSE" and "GRAPHIC ARC" give me an Ellipse at either 90 degrees or 0 degrees, but I can not get 30 degrees, or 45, or 60 or other.

    To my understanding it is because the ellipse uses the X side as 1 axis, and the Y side as the other axis (So for example X = Minor Axis, Y = Major Axis

    My problem is if my Major Axis is 135 degrees (90 + 45) and my Y is 45 degrees (0 + 45) how to get an ellipse when I can not change the orientation of the binding square?

    Hopefully the question is not toooo convoluted, and someone gets what I am trying to do and can offer a formula, or some idea how to draw an ellipse that is not "Up-Down" or "Left-Right"
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

  • #2
    Actually understood what you're asking, you want to "rotate" the ellipse in the destination by a factor in which the ellipse is not drawn "square" to the bounding rectangle. And, at least as much as I understand such transformations, cannot be done easily.

    http://edais.mvps.org/Tutorials/GDI/DC/ and read chapter 8, while it's done with VB, it gives the principles of world transforms. Probably what will interest you the most will be at the end of the chapter, where it deals with rotating an ellipse.
    Furcadia, an interesting online MMORPG in which you can create and program your own content.

    Comment


    • #3
      May be you can use some of these API functions:

      http://msdn.microsoft.com/en-us/libr...31(VS.85).aspx

      Best regards,

      Erik

      Comment


      • #4
        Cliff,
        try this:
        Code:
        'PBCC5.01 program 
        #COMPILE EXE
        #REGISTER NONE
        #DIM ALL
        
        TYPE PolyPoint
          x AS SINGLE
          y AS SINGLE
        END TYPE
        
        TYPE PolyArray
          COUNT AS LONG
          xy(0 TO 1024) AS PolyPoint   'note, this 1024 represents the maximum points that can be handled
        END TYPE
                         
                         
                         
        FUNCTION PBMAIN () AS LONG
        LOCAL MyPolygon AS PolyArray
        LOCAL hWin AS DWORD
        LOCAL r AS EXT
        
        GRAPHIC WINDOW "Ellipse", 100, 100, 800, 400  TO hWin
        GRAPHIC ATTACH hWin???, 0
        
        MyPolygon.count = 200  'set the number of points to calculate
        
        FOR r = 1 TO 360 STEP 1
            calculateEllipse( 100,100,20,100,r,MyPolygon)
            GRAPHIC POLYGON MyPolygon  ,%RED, %GREEN
            
            calculateEllipse( r*2,300,20,100,r,MyPolygon)
            GRAPHIC POLYGON MyPolygon  ,%RED, %GREEN
            SLEEP 10
        NEXT
        
        WAITKEY$
        
        END FUNCTION
        
        
        
        SUB calculateEllipse(x AS EXT, y AS EXT, a AS EXT, b AS EXT, angle AS EXT, ReturnArray AS PolyArray)
        'based on algorithm found here: http://en.wikipedia.org/wiki/Ellipse
        'x = x axis offset
        'y = y axis offset
        'a = semimajor axis of ellipse
        'b = semiminor axis of ellipse
        'angle = angle to the x-axis to draw ellipse in degrees
        
        
        LOCAL beta, cosbeta, sinbeta AS EXT
        LOCAL alpha, cosalpha, sinalpha AS EXT
        LOCAL DegToRad AS EXT
        LOCAL i AS EXT
        LOCAL index AS LONG
        
        DegToRad = 3.14159265358979323 / 180
        
        beta = -angle * DegToRad
        sinbeta = SIN(beta)
        cosbeta = COS(beta)
        
        FOR i = 0 TO 360 STEP (360/ReturnArray.count)
            alpha = i * DegToRad
            sinalpha = SIN(alpha)
            cosalpha = COS(alpha)
        
            ReturnArray.xy(index).x = x + (a * cosalpha * cosbeta - b * sinalpha * sinbeta)
            ReturnArray.xy(index).y = y + (a * cosalpha * sinbeta + b * sinalpha * cosbeta)
            
            INCR index
        
        NEXT
        
        END SUB
        Paul.

        Comment


        • #5
          To use Paul Dixon's program with PB 9.
          Change:
          Code:
          WAITKEY$
          To:
          Code:
          GRAPHIC WAITKEY$

          Comment


          • #6
            Paul beat me to it but here's another take on that Wikipedia algorithm. (PBWin)
            Code:
            #DIM ALL
            #Compile Exe
            #Include "WIN32API.INC"
             
            %GFX_C1     = 101
            %TXT_Angle  = 102
             Macro Pi   = 3.141592653589793##
            '------------------/
             
            Function DrawEllipse (ByVal hWin As Long, ByVal nID As Long, _
                                 Opt ByVal xAxis As long, ByVal yAxis As long, ByVal L As Double ) As Long 
             Local Cx, Cy As Long 
             Local i, alpha, beta, Lx, Ly, XX, YY As Double
              Graphic Attach hWin, nID
              Graphic Clear
              Graphic Get Client To Cx, Cy
             
              xAxis = IIF(xAxis = 0, Cx - Cx/5, xAxis)        ' if not specified xAxis = 80%
              yAxis = IIF(yAxis = 0, Cy - Cy/2, yAxis)        ' if not specified yAxis = 50%
              L = IIF(L = 0, 0, L)                            ' if not specified angle = 0
             
              beta = L * Pi/180                               ' converts Degree Value into Radians
             
              Lx = Cx/2 - xAxis/2 : ly = Cy/2
             
              for i = 0 To 360 'Step 10 
             
                alpha = i * Pi/180
             
                XX = Cx/2 + (xAxis/2 * Cos(alpha) * Cos(beta) - yAxis/2 * Sin(alpha) * Sin(beta))
                YY = Cy/2 + (xAxis/2 * Cos(alpha) * Sin(beta) + yAxis/2 * Sin(alpha) * Cos(beta))
             
                If i > 0 Then                                ' Skip line to first point)
                  GRAPHIC LINE (Lx, Ly) - (XX, YY), %RED
                End If
                Lx = XX : Ly = YY
                'Sleep 10
              next
             
            End Function 
            '------------------/DrawElipse
             
            CallBack Function DlgProc() As Long
             Local Angle As String 
              Select Case CbMsg
             
                Case %WM_Command
                  Select Case CbCtl 
                    Case %IDOK
                      If CbCtlMsg = %BN_Clicked Or CbCtlMsg = 1 Then
                        Control Get Text CbHndl, %TXT_Angle To Angle
                        DrawEllipse CbHndl, %GFX_C1, 0, 0, Val(Angle)
                        'DrawEllipse CbHndl, %GFX_C1                         ' eg
                        'DrawEllipse CbHndl, %GFX_C1, 250, 130, 60           ' eg
                        Control Send CbHndl, %TXT_Angle, %EM_SETSEL, 0, -1
                      End If
             
                    Case %IDCANCEL
                      If CbCtlMsg = %BN_Clicked Or CbCtlMsg = 1 Then
                        Dialog End CbHndl, 0
                      End If
                  End Select
             
                Case %WM_Destroy
             
              End Select
            End Function
            '------------------/DlgProc
             
            Function PBMain() As Long
             Local hDlg As Dword
             
              Dialog New Pixels, 0, "Test", 130, 145, 360, 340, %WS_CAPTION OR %WS_SYSMENU, TO hDlg
                Control Add Graphic, hDlg, %GFX_C1, "", 50, 25, 260, 260, %WS_CHILD OR %WS_VISIBLE OR _
                  %SS_OWNERDRAW OR %WS_BORDER
                Control Add Textbox, hDlg, %TXT_Angle, "45", 75, 301, 45, 21
                Control Add Button,  hDlg, %IDOK, "Draw", 142, 301, 76, 24
                Control Add Button,  hDlg, %IDCANCEL, "&Close", 255, 301, 75, 24
                Control Add Label,   hDlg, -1, "Deg", 30, 304, 38, 16
             
              Dialog Show Modal hDlg, Call DlgProc
             
            End Function
            '------------------/PBMain
            Rgds, Dave

            Comment


            • #7
              Thank you sooooooooooooooooooo much!!!!!!!!!!!!

              I should have thought about wikipedia, but have been googling for 2 days now over every college/mathematics/engineering page I could find, trying to develop an algorithm to draw the ellipse, but could not get it.

              Thanks again.....you guys ROCK :rockwoot:
              Engineer's Motto: If it aint broke take it apart and fix it

              "If at 1st you don't succeed... call it version 1.0"

              "Half of Programming is coding"....."The other 90% is DEBUGGING"

              "Document my code????" .... "WHYYY??? do you think they call it CODE? "

              Comment


              • #8
                > should have thought about wikipedia

                You should have thought about paying attention in geometry class, too.
                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  Originally posted by Michael Mattias View Post
                  > should have thought about wikipedia

                  You should have thought about paying attention in geometry class, too.
                  Mr Zale? Oh, Mr Zale? Where are you? Cleanup on aisle 4.

                  ================================
                  "Reality is merely an illusion,
                  albeit a very persistent one."
                  Albert Einstein (1879-1955)
                  ================================
                  Last edited by Gösta H. Lovgren-2; 9 Apr 2009, 07:38 PM.
                  It's a pretty day. I hope you enjoy it.

                  Gösta

                  JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                  LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                  Comment


                  • #10
                    You should have thought about paying attention in geometry class, too.
                    One word ---> SOHCAHTOA

                    Thats all I remember from geometry class over 20 years ago.

                    Mr Zale? Oh, Mr Zale? Where are you? Cleanup on aisle 4.

                    "Not a graphics man", spilling waterpaints in Aisle 4 again???
                    Engineer's Motto: If it aint broke take it apart and fix it

                    "If at 1st you don't succeed... call it version 1.0"

                    "Half of Programming is coding"....."The other 90% is DEBUGGING"

                    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                    Comment


                    • #11
                      =Michael Mattias;313525You should have thought about paying attention in geometry class, too.
                      I remember and its been 40 years, just can't find where in my computer I should put those two pins and the piece of string. Should I be connecting via USB?

                      Comment


                      • #12
                        Going back to the subject

                        Code:
                         
                        #COMPILE EXE
                        '#CONSOLE OFF   uncomment if PBCC5
                        DEFLNG a-z
                         
                        SUB DRWELLIP(xc%,yc%,a%,b%,ia%,fa%,fi!)    'center x, center y, dia a, dia b, arc ini, arc end, angle
                         LOCAL hh%,x!,y!
                         FOR hh%=ia% TO fa%
                          x!=xc%+a%*COS(hh%/1000)*COS(fi!)-b%*SIN(hh%/1000)*SIN(fi!)
                          y!=yc%+a%*COS(hh%/1000)*SIN(fi!)+b%*SIN(hh%/1000)*COS(fi!)
                          GRAPHIC LINE (x!,y!)-(x!+1,y!+1),%RED
                         NEXT
                         GRAPHIC REDRAW
                        END SUB
                         
                         
                        FUNCTION PBMAIN () AS LONG
                         DESKTOP GET CLIENT TO PixW,PixH
                         x1=0
                         y1=0
                         x2=PixW
                         y2=PixH
                         DESKTOP GET SIZE TO WinX,WinY
                         GRAPHIC WINDOW caption$,x1,y1,x2,y2 TO hwin
                         GRAPHIC ATTACH hwin,0,REDRAW
                         GRAPHIC SET LOC -2,0
                         GRAPHIC CLEAR %WHITE
                         GRAPHIC WIDTH 1
                         FOR hh%=0 TO 360 STEP 10
                          fi!=hh%*0.0174533
                          CALL DRWELLIP(200+2*hh%,200,100,60,0,6283,fi!)
                          GRAPHIC WAITKEY$ TO HK$
                         NEXT
                         fi!=30*0.0174533
                         CALL DRWELLIP(200,500,100,60,3142,6283,fi!)
                         GRAPHIC WAITKEY$ TO HK$
                         fi!=45*0.0174533
                         CALL DRWELLIP(400,500,100,60,3142,6283,fi!)
                         GRAPHIC WAITKEY$ TO HK$
                         fi!=60*0.0174533
                         CALL DRWELLIP(600,500,100,60,3142,6283,fi!)
                         GRAPHIC WAITKEY$ TO HK$
                         fi!=75*0.0174533
                         CALL DRWELLIP(800,500,100,60,3142,6283,fi!)
                         GRAPHIC WAITKEY$ TO HK$
                         fi!=90*0.0174533
                         CALL DRWELLIP(1000,500,100,60,3142,6283,fi!)
                         GRAPHIC WAITKEY$ TO HK$
                         fi!=30*0.0174533
                         CALL DRWELLIP(200,800,100,60,0,3142,fi!)
                         GRAPHIC WAITKEY$ TO HK$
                         fi!=45*0.0174533
                         CALL DRWELLIP(400,800,100,60,0,3142,fi!)
                         GRAPHIC WAITKEY$ TO HK$
                         fi!=60*0.0174533
                         CALL DRWELLIP(600,800,100,60,0,3142,fi!)
                         GRAPHIC WAITKEY$ TO HK$
                         fi!=75*0.0174533
                         CALL DRWELLIP(800,800,100,60,0,3142,fi!)
                         GRAPHIC WAITKEY$ TO HK$
                         fi!=90*0.0174533
                         CALL DRWELLIP(1000,800,100,60,0,3142,fi!)
                         GRAPHIC WAITKEY$ TO HK$
                        END FUNCTION
                        Last edited by Manuel Valdes; 14 Apr 2009, 10:53 AM.

                        Comment

                        Working...
                        X