How to create random polys

BlitzMax Forums/BlitzMax Beginners Area/How to create random polys

altitudems(Posted 2005) [#1]
I'm trying to create random astroid looking polys but the code below will not work. It just creates vertices on the bottom right quarter of the poly, and disregards the wanted radius of the poly. My math might be screwed up, but it shouldn't be. Why Doesn't this work?
	Method BuildPoly:tVector2[] (NumVertices:Int, radius:Float)
		Local Vertices:tVector2[NumVertices]
		
		For Local i:Int = 0 to NumVertices - 1
			Local a:Float = 2.0 * pi * (i / Float(NumVertices))
			Vertices[i] = tVector2.Create(Cos(a), Sin(a))
			Vertices[i].Mult(radius)
		Next
		Return Vertices
	End Method

Any help would be great!


fredborg(Posted 2005) [#2]
It looks like you are using radians instead of degrees. Try this instead:
Local a:Float = 360.0 * (i / Float(NumVertices))


altitudems(Posted 2005) [#3]
DOH :)

Thanks for the quick reply. Works like a charm.