UnderwareDESIGN

PlayBASIC => Resources => Source Codes => Topic started by: monkeybot on April 04, 2015, 06:36:30 AM

Title: Rotating Ellipse
Post by: monkeybot on April 04, 2015, 06:36:30 AM
I was wondering how to mathmatically rotate an ellipse for a prog i am writing so here it is...


[PBcode]; PROJECT : angled ellipse
; AUTHOR  : Monkeybot
; CREATED : 04/04/2015
; EDITED  : 04/04/2015
; ---------------------------------------------------------------------
setfps(50)
repeat

   for a=0 to 360
   cls
   plotellipse(400,300,150,100,a)
   sync
   next
until false



Function plotEllipse(mx#,my#,a#,b#,theta#)
   for t#=0 to 360 step 5
        local x#= a#*  ( cos(t#) * cos(theta#) ) -(b#*( sin(t#) * sin(theta#) ))
        local y#= a#*  ( cos(t#) * sin(theta#) ) +(b#*( sin(t#) * cos(theta#) ))  
        circlec mx#+x#,my#+y#,5,1,$0000ff
   next
EndFunction

[/PBcode]
Title: Re: Rotating Ellipse
Post by: kevin on April 04, 2015, 09:11:05 AM
  Here's a version that builds an ellipse shaped shape.  


[pbcode]

   ThisShape=CreateEllipseShape(100,50,30)


   Do
      cls

      Angle#=wrapangle(Angle#,0.25)
      rotateShape  ThisShape,Angle#,1
      drawshape ThisShape,400,300,1

      Sync
   loop esckey()=true




Function CreateEllipseShape(RadiusX,RAdiusY,Samples)

   ThisShape= newshape(Samples+1,Samples+1)
   
   local lp,Scaler#=360.0/samples

   // set up the vertex   and edges
   for lp=0 to Samples-1
   
      local vx#=cos(Scaler#*lp)*RAdiusX
      local vy#=sin(Scaler#*lp)*RAdiusY
      
      SetshapeVertex THisShape,lp,vx#,vy#
   
      SetShapeEdge ThisShape,lp,lp,mod(lp+1,Samples)
   
   next
   
   refreshshape ThisShape

EndFunction ThisShape

[/pbcode]