/// <summary>
 /// Creates a new Circle Instance.
 /// </summary>
 /// <param name="radius">how large the circle is.</param>
 /// <param name="vertexCount">
 /// The number or vertex that will be generated along the perimeter of the circle.
 /// This is for collision detection.
 /// </param>
 /// <param name="momentOfInertiaMultiplier">
 /// How hard it is to turn the shape. Depending on the construtor in the
 /// Body this will be multiplied with the mass to determine the moment of inertia.
 /// </param>
 public CircleShape(Scalar radius, int vertexCount, Scalar momentOfInertiaMultiplier)
     : base(CreateCircle(radius, vertexCount), momentOfInertiaMultiplier)
 {
     if (radius <= 0)
     {
         throw new ArgumentOutOfRangeException("radius", "must be larger then zero");
     }
     this.radius  = radius;
     this.Normals = ShapeHelper.CalculateNormals(this.Vertexes);
 }
        private Vector2D[] CalculateNormals()
        {
            Vector2D[] result = new Vector2D[Vertexes.Length];
            int        offset = 0;

            for (int index = 0; index < polygons.Length; ++index)
            {
                Vector2D[] polygon = polygons[index];
                ShapeHelper.CalculateNormals(polygon, result, offset);
                offset += polygon.Length;
            }
            return(result);
        }
 /// <summary>
 /// Creates a new Polygon Instance.
 /// </summary>
 /// <param name="vertexes">the vertexes that make up the shape of the Polygon</param>
 /// <param name="gridSpacing">
 /// How large a grid cell is. Usualy you will want at least 2 cells between major vertexes.
 /// The smaller this is the better precision you get, but higher cost in memory.
 /// The larger the less precision and if it's to high collision detection may fail completely.
 /// </param>
 /// <param name="momentOfInertiaMultiplier">
 /// How hard it is to turn the shape. Depending on the construtor in the
 /// Body this will be multiplied with the mass to determine the moment of inertia.
 /// </param>
 public PolygonShape(Vector2D[] vertexes, Scalar gridSpacing, Scalar momentOfInertiaMultiplier)
     : base(vertexes, momentOfInertiaMultiplier)
 {
     if (vertexes == null)
     {
         throw new ArgumentNullException("vertexes");
     }
     if (vertexes.Length < 3)
     {
         throw new ArgumentException("too few", "vertexes");
     }
     if (gridSpacing <= 0)
     {
         throw new ArgumentOutOfRangeException("gridSpacing");
     }
     this.Normals = ShapeHelper.CalculateNormals(this.Vertexes);
     this.grid    = new DistanceGrid(this, gridSpacing);
 }