Drawing Arcs

Everything else that doesn't fall into one of the other PB categories.
Ollivier
Enthusiast
Enthusiast
Posts: 281
Joined: Mon Jul 23, 2007 8:30 pm
Location: FR

Post by Ollivier »

Code: Select all

xCenter FLOAT (pixel)
yCenter FLOAT (pixel)
xRadius FLOAT (pixel)
yRadius FLOAT (pixel)
zRotation FLOAT (rad)
StartAngle FLOAT (rad)
FinishAngle FLOAT (rad)

Code: Select all

Procedure EllipseWithRotation(xCenter.F, yCenter.F, xRadius.F, yRadius.F, zRotation.F, StartAngle.F, FinishAngle.F, Color.L)
    Protected Angle.F
    Protected AngleStep.F    
    Protected X.F
    Protected Y.F
    Protected DisplayX.F
    Protected DisplayY.F
    Protected GreatestRadius.F
    If xRadius > yRadius
        GreatestRadius.F = xRadius
    Else
        GreatestRadius = yRadius
    EndIf
    AngleStep.F = #PI / GreatestRadius
    NewList DrawX.POINT()
    Angle = StartAngle
    Repeat        
        X.F = Cos(Angle) * xRadius                           ; Draw an ellipse...
        Y.F = -Sin(Angle) * yRadius
        DisplayX.F = X * Cos(zRotation) - Y * Sin(zRotation) ; Rotation...
        DisplayY.F = X * Sin(zRotation) + Y * Cos(zRotation)        
        AddElement(DrawX() )                                 ; Record...
        DrawX()\X = xCenter + DisplayX
        DrawX()\Y = yCenter + DisplayY        
        Angle + AngleStep        
    Until Angle > FinishAngle
    ResetList(DrawX() )                                      ; Draw...
    For i = 1 To CountList(DrawX() ) - 1        
        SelectElement(DrawX(), i - 1)
        x1 = DrawX()\X
        y1 = DrawX()\Y
        SelectElement(DrawX(), i)
        x2 = DrawX()\X
        y2 = DrawX()\Y
        LineXY(x1, y1, x2, y2, Color)        
    Next
    ClearList(DrawX() )
EndProcedure
Nice day!
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

Look Ma! No API.... ;)

Well done, thanks a lot Ollivier! Your usage of lists forces me to re-think parts of an application that I'm currently developing. Thanks again.
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
Ollivier
Enthusiast
Enthusiast
Posts: 281
Joined: Mon Jul 23, 2007 8:30 pm
Location: FR

Post by Ollivier »

Indeed, lists offer many possibilities :D
Ollivier
Enthusiast
Enthusiast
Posts: 281
Joined: Mon Jul 23, 2007 8:30 pm
Location: FR

Post by Ollivier »

2 Xombie (or somebody who knows the answer)

What is 'anti-aliased' ???
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

Ollivier,

check out: http://en.wikipedia.org/wiki/Xiaolin_Wu ... _algorithm

Xiaolin Wu's algorithm is one of many anti-aliassing techniques.

bye
Hans
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
Ollivier
Enthusiast
Enthusiast
Posts: 281
Joined: Mon Jul 23, 2007 8:30 pm
Location: FR

Post by Ollivier »

So, reading the wikipedia's article, I think I answer Xombie enough correctly... With a list! He'll have just to manage the 2 lines 'NewList' and 'ClearList' to recuperate coordonates x and y arcs...

Thanks
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Post by Xombie »

Thanks, everyone! I'm excited to try this out tonight and see what kind of damage I can do.

So, yes, thanks again for being patient with me even though I'm quite slow at stuff like this :p

Thanks again, Ollivier, Helle and Kaeru Gaman!
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Is there any reason you don't use the API function Arc_()?
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Post by Xombie »

@Trond - because GDI+ and the Arc_() command are both bound by a rectangle which means the ellipse is either elongated on the x or y axis. I need to set the elongated edge around the z axis, if that makes sense. It's for a silly little program that I'm working on on the side ^_^

@Ollivier - it works although I had to scare up a quick old memory on coordinate systems to vaguely remember something about degrees and radians :)

I especially like being able to have points available as I was hoping to color different parts different colors.

Thanks so much!
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Xombie wrote:@Trond - because GDI+ and the Arc_() command are both bound by a rectangle which means the ellipse is either elongated on the x or y axis. I need to set the elongated edge around the z axis, if that makes sense. It's for a silly little program that I'm working on on the side ^_^
Did you try RotateDC_()?
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Post by Xombie »

I haven't heard of RotateDC_() and it doesn't seem to show up on MSDN.

Do you have links to any more information?

Thanks!
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Sorry, RotateDC() was I function I had written myself. I meant SetWorldTransform_().

Code: Select all

Procedure RotateDC(hDC.l, x0.l, y0.l, Degrees.d)
  Static XFORM.XFORM
  Protected Radians.d = Degrees*(#PI/180)
  With XFORM
    \eM11 = Cos(Radians)
    \eM12 = Sin(Radians)
    \eM21 = -\eM12
    \eM22 = \eM11
    \ex = x0 - Cos(Radians)*x0 + Sin(Radians)*y0
    \ey = y0 - Cos(Radians)*y0 - Sin(Radians)*x0
  EndWith
  SetGraphicsMode_(hDC, #GM_ADVANCED)
  SetWorldTransform_(hDC, XFORM)
EndProcedure
Ollivier
Enthusiast
Enthusiast
Posts: 281
Joined: Mon Jul 23, 2007 8:30 pm
Location: FR

Post by Ollivier »

2Trond

Have you got an example of using RotateDC() ?

What is XFORM structure?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Code: Select all

Procedure RotateDC(hDC.l, x0.l, y0.l, Degrees.d) 
  Static XFORM.XFORM 
  Protected Radians.d = Degrees*(#PI/180) 
  With XFORM 
    \eM11 = Cos(Radians) 
    \eM12 = Sin(Radians) 
    \eM21 = -\eM12 
    \eM22 = \eM11 
    \eDx = x0 - Cos(Radians)*x0 + Sin(Radians)*y0 
    \eDy = y0 - Cos(Radians)*y0 - Sin(Radians)*x0 
  EndWith 
  SetGraphicsMode_(hDC, #GM_ADVANCED) 
  SetWorldTransform_(hDC, XFORM) 
EndProcedure


OpenWindow(0, 0, 0, 384, 384, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_Repaint
      hDC = StartDrawing(WindowOutput(0))
        Line(100, 100, 200, 0, #Red)
        RotateDC(hDC, WindowWidth(0)/2, WindowHeight(0)/2, 90)
        Line(100, 100, 200, 0, #Blue)
        RotateDC(hDC, WindowWidth(0)/2, WindowHeight(0)/2, 180)
        Line(100, 100, 200, 0, #Green)
      StopDrawing()
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver



Ollivier
Enthusiast
Enthusiast
Posts: 281
Joined: Mon Jul 23, 2007 8:30 pm
Location: FR

Post by Ollivier »

To run your code, I replaced the 2 lines

Code: Select all

    \eDx = x0 - Cos(Radians)*x0 + Sin(Radians)*y0 
    \eDy = y0 - Cos(Radians)*y0 - Sin(Radians)*x0 
 
with

Code: Select all

    \ex = x0 - Cos(Radians)*x0 + Sin(Radians)*y0 
    \ey = y0 - Cos(Radians)*y0 - Sin(Radians)*x0 
 
It's exactly what Xombie could use with the API Ellipse drawing function!
But I ignore the XFORM structure. Has it other variables. Its variables are they in function of the functions using it, or do they have a independant mean?
Post Reply