FarseerPhysics.Common.PolygonTools.createGear C# (CSharp) Method

createGear() public static method

Creates a gear shape with the specified radius and number of teeth.
public static createGear ( float radius, int numberOfTeeth, float tipPercentage, float toothHeight ) : Vertices
radius float The radius.
numberOfTeeth int The number of teeth.
tipPercentage float The tip percentage.
toothHeight float Height of the tooth.
return Vertices
		public static Vertices createGear( float radius, int numberOfTeeth, float tipPercentage, float toothHeight )
		{
			var vertices = new Vertices();

			float stepSize = MathHelper.TwoPi / numberOfTeeth;
			tipPercentage /= 100f;
			MathHelper.Clamp( tipPercentage, 0f, 1f );
			float toothTipStepSize = ( stepSize / 2f ) * tipPercentage;

			float toothAngleStepSize = ( stepSize - ( toothTipStepSize * 2f ) ) / 2f;

			for( int i = numberOfTeeth - 1; i >= 0; --i )
			{
				if( toothTipStepSize > 0f )
				{
					vertices.Add(
						new Vector2( radius *
									(float)Math.Cos( stepSize * i + toothAngleStepSize * 2f + toothTipStepSize ),
									-radius *
									(float)Math.Sin( stepSize * i + toothAngleStepSize * 2f + toothTipStepSize ) ) );

					vertices.Add(
						new Vector2( ( radius + toothHeight ) *
									(float)Math.Cos( stepSize * i + toothAngleStepSize + toothTipStepSize ),
									-( radius + toothHeight ) *
									(float)Math.Sin( stepSize * i + toothAngleStepSize + toothTipStepSize ) ) );
				}

				vertices.Add( new Vector2( ( radius + toothHeight ) *
										 (float)Math.Cos( stepSize * i + toothAngleStepSize ),
										 -( radius + toothHeight ) *
										 (float)Math.Sin( stepSize * i + toothAngleStepSize ) ) );

				vertices.Add( new Vector2( radius * (float)Math.Cos( stepSize * i ),
										 -radius * (float)Math.Sin( stepSize * i ) ) );
			}

			return vertices;
		}