Rotate around origin

BlitzMax Forums/BlitzMax Beginners Area/Rotate around origin

Hi.

How can I calculate the position of an object which rotates around the origin or an other point on the screen.
for example if I want to draw an oval at the position 300,400 at the beginning an then it should rotate around the origin.
How can I calculate the position depending on the angle of the rotation?
Sry, I'm not that good in Trigonometry^^
Thank you.
Lukasha..

Plot xPos + ( Sin(angle)*radius ),yPos - ( Cos(angle)*radius  )


EDIT: I'm assuming you mean a circle and not an oval; xPos and yPos are the x and y of the origin, obv.

This should help.

Thx, you helped me..

You could use Max2D's handle system...
Strict

Type TPoint2D
	Field x#, y#
End Type

Type TVectObj
	Field originX#, originY#
	Field scaleX# = 1, scaleY# = 1
	Field rotation#, alpha# = 1
	Field r, g, b
	
	Field points:TPoint2D[]
	
	Method AddPoint(x#, y#)
		Local thisPoint:TPoint2D = New TPoint2D
		thisPoint.x# = x#
		thisPoint.y# = y#
		
		points = points[..points.length + 1]
		points[points.length - 1] = thisPoint
	End Method
	
	Method SetColour(r, g, b)
		Self.r = r
		Self.g = g
		Self.b = b
	End Method
	
	Method SetScale(x#, y#)
		scaleX# = x#
		scaleY# = y#
	End Method
	
	Method Draw()
		SetTransform rotation#, scaleX#, scaleY#
		SetColor r, g, b
		
		For Local thisPoint = 0 Until points.length
			Local nextPoint = (thisPoint + 1) Mod points.length
			Local handleX# = originX# - (originX# + points[thisPoint].x#)
			Local handleY# = originY# - (originY# + points[thisPoint].y#)
			
			SetHandle handleX#, handleY#
			DrawLine originX# ,originY#,..
							(originX# + Points[nextPoint].x#) + handleX#,..
							(originY# + Points[nextPoint].y#) + handleY#
		Next
	End Method
End Type

Type TPlayer
	Field ship:TVectObj
	Field vx#, vy#
	
	Function Create:TPlayer(ship:TVectObj, x#, y#)
		Local thisPlayer:TPlayer = New TPlayer
		
		thisPlayer.ship = ship
		thisPlayer.ship.originX# = x#
		thisPlayer.ship.originY# = y#
		
		Return thisPlayer
	End Function
	
	Method Update()	
		If KeyDown(KEY_LEFT)
			ship.rotation# :- 4
		EndIf
		
		If KeyDown(KEY_RIGHT)
			ship.rotation# :+ 4
		EndIf
		
		If KeyDown(KEY_UP)
			vx# :+ Sin(ship.rotation#) * 0.1
		 	vy# :- Cos(ship.rotation#) * 0.1
		
			Local vectMag! = Sqr((vx# * vx#) + (vy# * vy#))
			If vectMag! > 10.0
				vx# = (vx# / vectMag!) * 10.0
				vy# = (vy# / vectMag!) * 10.0
			EndIf
		Else
			vx# :* 0.99
			vy# :* 0.99
		EndIf
		
		ship.originX# :+ vx#
		ship.originY# :+ vy#
		
		If ship.originX# < 0
			ship.originX# = GraphicsWidth()
		Else
			If ship.originX# > GraphicsWidth() Then ship.originX# = 0
		EndIf
		
		If ship.originY# < 0
			ship.originY# = GraphicsHeight()
		Else
			If ship.originY# > GraphicsHeight() Then ship.originY# = 0
		EndIf	
	End Method
	
	Method Draw()
		ship.Draw()
	End Method	
End Type		
		
	
SetGraphicsDriver GLMax2DDriver()
Graphics 800, 600, 0'32
HideMouse

Local ship:TVectObj = New TVectObj
ship.AddPoint(0, -10)
ship.AddPoint(10, 10)
ship.AddPoint(0, 7.5)
ship.AddPoint(-10, 10)
ship.SetColour(200, 255, 255)

Local player:TPlayer = TPlayer.Create(ship, 400, 300)

glEnable(GL_LINE_SMOOTH)
SetLineWidth 2'0.25

Repeat
	Clear()
	
	'ship.SetScale(1 + (Cos(MilliSecs() * 1.5) * 0.1), 1 + (Sin(MilliSecs() * 1.5) * 0.1))	
	player.Update()
	
	SetAlpha 0.5
	player.Draw()
	
	'FlushMem
	
	Flip
Until KeyHit(KEY_ESCAPE)

End

Function Clear(alpha#=0.6) 
	SetColor 0, 0, 0
	SetHandle 0, 0
	SetTransform 0, 1, 1
	SetBlend ALPHABLEND
	SetAlpha alpha#
	DrawRect 0, 0, 800, 600
End Function

...Not a particularly clear example but it was to hand. You should pay particular attention to 'TVectObj.Draw()' and bear in mind that the current 'system scale' will also play a part.