Point on an angled ellipse

Monkey Forums/Monkey Programming/Point on an angled ellipse

Raz(Posted 2013) [#1]
Hopefully this makes sense.



The first ellipse is probably something like...

Local originX:Float = 10
Local originY:Float = 10

For Local angle:Int = 0 Until 360
  x = originX + Sin(angle) * 0.5
  y = originY + Cos(angle)
Next


But how would I work out the points on the second ellipse (which is tilted by approx 45 degrees)

Ta! :)
-Chris


Goodlookinguy(Posted 2013) [#2]
You should learn about matrices, they're really nice.

Import mojo

Function Main:Int()
	New Example()
End

Class Example Extends App
	Method OnCreate()
		SetUpdateRate(30)
	End
	Method OnRender()
		Cls()
		Local x:Float, y:Float, xx:Float, yy:Float
		Local rotation:Int = 135
		Local length:Int = 30
		Local originX:Float = 100
		Local originY:Float = 100
		
		For Local angle:Int = 0 Until 360
			x = originX + length * Sin(angle) * 0.5
			y = originY + length * Cos(angle)
			DrawPoint(x, y)
		Next
		
		originX = 160
		originY = 100
		
		For Local angle:Int = 0 Until 360
			xx = length * Sin(angle) * 0.5
			yy = length * Cos(angle)
			x = Cos(rotation) * xx - Sin(rotation) * yy + originX
			y = Sin(rotation) * xx + Cos(rotation) * yy + originY
			DrawPoint(x, y)
		Next
	End
End
Note: Your example is actually 135 degrees.

Edit: I cleaned up the code a little to make it easier to understand.


Midimaster(Posted 2013) [#3]
*** EDIT ***
sorry, wrong answer...

*** EDIT ***


Gerry Quinn(Posted 2013) [#4]
Just find the point on a non-angled ellipse, and then rotate it by the appropriate angle around the centre of the ellipse.

E.g.
dx1 = Cos( angle ) * rad * 0.5
dy1 = Sin( angle ) * rad
x = originX + dx1 * Cos( 45 ) - dy1 * Sin( 45 )
y = originY + dx1 * Sin( 45 ) + dy1 * Cos( 45 )

Obviously you can simplify a bit. I haven't tested it but it should work though you might have to reverse a sign or two depending on your coordinate system.


Raz(Posted 2013) [#5]
Nice one, thanks all :D


John Galt(Posted 2013) [#6]
...or something like...
Local originX:Float = 10
Local originY:Float = 10
Local rot:Float = 45 'The angle by which the ellipse is rotated

For Local angle:Int = 0 Until 360
  x = originX + Sin(angle-rot) * 0.5
  y = originY + Cos(angle-rot)
Next
<untested>