Jypeli  9
The simple game programming library
VertexHelper.cs
Siirry tämän tiedoston dokumentaatioon.
1 #region MIT License
2 /*
3  * Copyright (c) 2005-2008 Jonathan Mark Porter. http://physics2d.googlepages.com/
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17  * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  */
22 #endregion
23 
24 
25 
26 
27 #if UseDouble
28 using Scalar = System.Double;
29 #else
30 using Scalar = System.Single;
31 #endif
32 using System;
33 using System.Collections.Generic;
34 using AdvanceMath;
36 
37 
38 namespace Jypeli.Physics2d
39 {
40 
41  public class VertexInfo
42  {
47  {
48  this.centroid = centroid;
49  this.inertia = inertia;
50  this.area = area;
51  }
53  {
54  get { return centroid; }
55  }
56  public Scalar Inertia
57  {
58  get { return inertia; }
59  }
60  public Scalar Area
61  {
62  get { return area; }
63  }
64  }
65 
66  public static class VertexHelper
67  {
68  public static Vector2D[] ApplyMatrix(ref Matrix2x3 matrix, Vector2D[] vertexes)
69  {
70  return OperationHelper.ArrayRefOp<Matrix2x3, Vector2D, Vector2D>(ref matrix, vertexes, Vector2D.Transform);
71  }
72  public static Vector2D[][] ApplyMatrixToRange(ref Matrix2x3 matrix, Vector2D[][] polygons)
73  {
74  if (polygons == null) { throw new ArgumentNullException("polygons"); }
75  Vector2D[][] result = new Vector2D[polygons.Length][];
76  for (int index = 0; index < polygons.Length; ++index)
77  {
78  result[index] = ApplyMatrix(ref matrix, polygons[index]);
79  }
80  return result;
81  }
82 
92  public static Vector2D[] CreateFromBitmap(bool[,] bitmap)
93  {
94  return CreateFromBitmap(new ArrayBitmap(bitmap));
95  }
96  public static Vector2D[] CreateFromBitmap(IBitmap bitmap)
97  {
98  if (bitmap == null) { throw new ArgumentNullException("bitmap"); }
99  if (bitmap.Width < 2 || bitmap.Height < 2) { throw new ArgumentOutOfRangeException("bitmap"); }
100  return BitmapHelper.CreateFromBitmap(bitmap);
101  }
102  public static Vector2D[][] CreateRangeFromBitmap(bool[,] bitmap)
103  {
104  return CreateRangeFromBitmap(new ArrayBitmap(bitmap));
105  }
106  public static Vector2D[][] CreateRangeFromBitmap(IBitmap bitmap)
107  {
108  if (bitmap == null) { throw new ArgumentNullException("bitmap"); }
109  if (bitmap.Width < 2 || bitmap.Height < 2) { throw new ArgumentOutOfRangeException("bitmap"); }
110  return BitmapHelper.CreateManyFromBitmap(bitmap);
111  }
118  public static Vector2D[] CreateRectangle(Scalar width, Scalar height)
119  {
120  if (width <= 0) { throw new ArgumentOutOfRangeException("width", "must be greater then 0"); }
121  if (height <= 0) { throw new ArgumentOutOfRangeException("height", "must be greater then 0"); }
122  Scalar wd2 = width * .5f;
123  Scalar ld2 = height * .5f;
124  return new Vector2D[4]
125  {
126  new Vector2D(wd2, ld2),
127  new Vector2D(-wd2, ld2),
128  new Vector2D(-wd2, -ld2),
129  new Vector2D(wd2, -ld2)
130  };
131  }
132  public static Vector2D[] CreateCircle(Scalar radius, int vertexCount)
133  {
134  if (radius <= 0) { throw new ArgumentOutOfRangeException("radius", "Must be greater then zero."); }
135  if (vertexCount < 3) { throw new ArgumentOutOfRangeException("vertexCount", "Must be equal or greater then 3"); }
136  Vector2D[] result = new Vector2D[vertexCount];
137  Scalar angleIncrement = MathHelper.TwoPi / vertexCount;
138  for (int index = 0; index < vertexCount; ++index)
139  {
140  Scalar angle = angleIncrement * index;
141  Vector2D.FromLengthAndAngle(ref radius, ref angle, out result[index]);
142  }
143  return result;
144  }
150  public static Scalar GetInertia(Vector2D[] vertexes)
151  {
152  return BoundingPolygon.GetInertia(vertexes);
153  }
154  public static Scalar GetInertiaOfRange(Vector2D[][] polygons)
155  {
156  if (polygons == null) { throw new ArgumentNullException("polygons"); }
157  if (polygons.Length == 0) { throw new ArgumentOutOfRangeException("polygons"); }
158  Scalar denom = 0;
159  Scalar numer = 0;
160  Scalar a, b, c, d;
161  Vector2D v1, v2;
162  for (int polyIndex = 0; polyIndex < polygons.Length; ++polyIndex)
163  {
164  Vector2D[] vertexes = polygons[polyIndex];
165  if (vertexes == null) { throw new ArgumentNullException("polygons"); }
166  if (vertexes.Length == 0) { throw new ArgumentOutOfRangeException("polygons"); }
167  if (vertexes.Length == 1) { break; }
168  v1 = vertexes[vertexes.Length - 1];
169  for (int index = 0; index < vertexes.Length; index++, v1 = v2)
170  {
171  v2 = vertexes[index];
172  Vector2D.Dot(ref v2, ref v2, out a);
173  Vector2D.Dot(ref v2, ref v1, out b);
174  Vector2D.Dot(ref v1, ref v1, out c);
175  Vector2D.ZCross(ref v1, ref v2, out d);
176  d = Math.Abs(d);
177  numer += d;
178  denom += (a + b + c) * d;
179  }
180  }
181  if (numer == 0) { return 1; }
182  return denom / (numer * 6);
183  }
184 
191  public static Vector2D[] GetIntersection(Vector2D[] vertexes, Scalar radius)
192  {
193  Scalar[] distances = new Scalar[vertexes.Length];
194  for (int index = 0; index < vertexes.Length; ++index)
195  {
196  distances[index] = vertexes[index].Magnitude - radius;
197  }
198  Scalar lastDistance = distances[distances.Length - 1];
199  Vector2D lastVertex = vertexes[vertexes.Length - 1];
200  Vector2D vertex;
201  Scalar distance;
202  List<Vector2D> result = new List<Vector2D>(vertexes.Length + 1);
203  for (int index = 0; index < vertexes.Length; ++index, lastVertex = vertex, lastDistance = distance)
204  {
205  vertex = vertexes[index];
206  distance = distances[index];
207  if (Math.Abs(Math.Sign(distance) - Math.Sign(lastDistance)) == 2)
208  {
209  Scalar lastABS = Math.Abs(lastDistance);
210  Scalar total = (lastABS + Math.Abs(distance));
211  Scalar percent = lastABS / total;
212  Vector2D intersection;
213  Vector2D.Lerp(ref lastVertex, ref vertex, ref percent, out intersection);
214  result.Add(intersection);
215  }
216  if (distance >= 0)
217  {
218  result.Add(vertex);
219  }
220  }
221  return result.ToArray();
222  }
223 
224  public static VertexInfo GetVertexInfo(Vector2D[] vertexes)
225  {
226  if (vertexes == null) { throw new ArgumentNullException("vertexes"); }
227  if (vertexes.Length < 3) { throw new ArgumentOutOfRangeException("vertexes"); }
228  Scalar area = 0;
229  Scalar denom = 0;
230  Scalar numer = 0;
231  Scalar a, b, c, d;
232  Vector2D centroid = Vector2D.Zero;
233  Vector2D v1 = vertexes[vertexes.Length - 1];
234  Vector2D v2;
235  for (int index = 0; index < vertexes.Length; index++, v1 = v2)
236  {
237  v2 = vertexes[index];
238  Vector2D.Dot(ref v2, ref v2, out a);
239  Vector2D.Dot(ref v2, ref v1, out b);
240  Vector2D.Dot(ref v1, ref v1, out c);
241  Vector2D.ZCross(ref v1, ref v2, out d);
242  area += d;
243  centroid.X += ((v1.X + v2.X) * d);
244  centroid.Y += ((v1.Y + v2.Y) * d);
245  d = Math.Abs(d);
246  numer += d;
247  denom += (a + b + c) * d;
248  }
249  area = Math.Abs(area * .5f);
250  d = 1 / (area * 6);
251  centroid.X *= d;
252  centroid.Y *= d;
253  return new VertexInfo(centroid, denom / (numer * 6), area);
254  }
255  public static VertexInfo GetVertexInfoOfRange(Vector2D[][] polygons)
256  {
257  if (polygons == null) { throw new ArgumentNullException("polygons"); }
258  if (polygons.Length == 0) { throw new ArgumentOutOfRangeException("polygons"); }
259  Scalar a, b, c, d;
260  Scalar denom = 0;
261  Scalar numer = 0;
262  Scalar areaTotal = 0;
263  Vector2D centroid = Vector2D.Zero;
264  for (int index1 = 0; index1 < polygons.Length; ++index1)
265  {
266  Vector2D[] vertexes = polygons[index1];
267  if (vertexes == null) { throw new ArgumentNullException("polygons"); }
268  if (vertexes.Length < 3) { throw new ArgumentOutOfRangeException("polygons", "There must be at least 3 vertexes"); }
269  Scalar area = 0;
270  Vector2D v1 = vertexes[vertexes.Length - 1];
271  Vector2D v2;
272  for (int index = 0; index < vertexes.Length; ++index, v1 = v2)
273  {
274  v2 = vertexes[index];
275  Vector2D.Dot(ref v2, ref v2, out a);
276  Vector2D.Dot(ref v2, ref v1, out b);
277  Vector2D.Dot(ref v1, ref v1, out c);
278  Vector2D.ZCross(ref v1, ref v2, out d);
279  area += d;
280  centroid.X += ((v1.X + v2.X) * d);
281  centroid.Y += ((v1.Y + v2.Y) * d);
282  d = Math.Abs(d);
283  numer += d;
284  denom += (a + b + c) * d;
285  }
286  areaTotal += Math.Abs(area);
287  }
288  areaTotal *= .5f;
289  d = 1 / (areaTotal * 6);
290  centroid.X *= d;
291  centroid.Y *= d;
292  return new VertexInfo(
293  centroid,
294  (numer == 0) ? (1) : (denom / (numer * 6)),
295  areaTotal);
296  }
297 
298  internal static void CalculateNormals(Vector2D[] vertexes, Vector2D[] normals, int offset)
299  {
300  Vector2D[] edges = new Vector2D[vertexes.Length];
301  Vector2D last = vertexes[0];
302  Vector2D current;
303  Vector2D temp;
304  for (int index = vertexes.Length - 1; index > -1; --index, last = current)
305  {
306  current = vertexes[index];
307  Vector2D.Subtract(ref current, ref last, out temp);
308  Vector2D.Normalize(ref temp, out temp);
309  Vector2D.GetRightHandNormal(ref temp, out edges[index]);
310  }
311  last = edges[vertexes.Length - 1];
312  for (int index = 0; index < vertexes.Length; ++index, last = current)
313  {
314  current = edges[index];
315  Vector2D.Add(ref current, ref last, out temp);
316  Vector2D.Normalize(ref temp, out normals[index + offset]);
317  }
318  }
319 
320 
321  public static Vector2D[] GetVertexNormals(Vector2D[] vertexes)
322  {
323  if (vertexes == null) { throw new ArgumentNullException("vertexes"); }
324  Vector2D[] result = new Vector2D[vertexes.Length];
325  CalculateNormals(vertexes, result, 0);
326  return result;
327  }
328  public static Vector2D[][] GetVertexNormalsOfRange(Vector2D[][] polygons)
329  {
330  if (polygons == null) { throw new ArgumentNullException("polygons"); }
331  Vector2D[][] result = new Vector2D[polygons.Length][];
332  for (int index = 0; index < polygons.Length; ++index)
333  {
334  result[index] = GetVertexNormals(polygons[index]);
335  }
336  return result;
337  }
338 
339 
340 
341  public static Vector2D[] GetIntersection(Vector2D[] vertexes, Line line)
342  {
343  Scalar[] distances = new Scalar[vertexes.Length];
344  for (int index = 0; index < vertexes.Length; ++index)
345  {
346  line.GetDistance(ref vertexes[index], out distances[index]);
347  }
348  Scalar lastDistance = distances[distances.Length - 1];
349  Vector2D lastVertex = vertexes[vertexes.Length - 1];
350  Vector2D vertex;
351  Scalar distance;
352  List<Vector2D> result = new List<Vector2D>(vertexes.Length + 1);
353  for (int index = 0; index < vertexes.Length; ++index, lastVertex = vertex, lastDistance = distance)
354  {
355  vertex = vertexes[index];
356  distance = distances[index];
357  if (Math.Abs(Math.Sign(distance) - Math.Sign(lastDistance)) == 2)
358  {
359  Scalar lastABS = Math.Abs(lastDistance);
360  Scalar total = (lastABS + Math.Abs(distance));
361  Scalar percent = lastABS / total;
362  Vector2D intersection;
363  Vector2D.Lerp(ref lastVertex, ref vertex, ref percent, out intersection);
364  result.Add(intersection);
365  }
366  if (distance >= 0)
367  {
368  result.Add(vertex);
369  }
370  }
371  return result.ToArray();
372  }
373 
380  public static Vector2D[] Subdivide(Vector2D[] vertexes, Scalar maxLength)
381  {
382  return Subdivide(vertexes, maxLength, true);
383  }
391  public static Vector2D[] Subdivide(Vector2D[] vertexes, Scalar maxLength, bool loop)
392  {
393  if (vertexes == null) { throw new ArgumentNullException("vertexes"); }
394  if (vertexes.Length < 2) { throw new ArgumentOutOfRangeException("vertexes"); }
395  if (maxLength <= 0) { throw new ArgumentOutOfRangeException("maxLength", "must be greater then zero"); }
396  LinkedList<Vector2D> list = new LinkedList<Vector2D>(vertexes);
397  LinkedListNode<Vector2D> prevNode, node;
398  if (loop)
399  {
400  prevNode = list.Last;
401  node = list.First;
402  }
403  else
404  {
405  prevNode = list.First;
406  node = prevNode.Next;
407  }
408  for (; node != null;
409  prevNode = node,
410  node = node.Next)
411  {
412  Vector2D edge = node.Value - prevNode.Value;
413  Scalar mag = edge.Magnitude;
414  if (mag > maxLength)
415  {
416  int count = (int)Math.Ceiling(mag / maxLength);
417  mag = 1f / count;
418  Vector2D.Multiply(ref edge, ref mag, out edge);
419  for (int pos = 1; pos < count; ++pos)
420  {
421  prevNode = list.AddAfter(prevNode, edge + prevNode.Value);
422  }
423  }
424  }
425  Vector2D[] result = new Vector2D[list.Count];
426  list.CopyTo(result, 0);
427  return result;
428  }
434  public static Vector2D[] Reduce(Vector2D[] vertexes)
435  {
436  return Reduce(vertexes, 0);
437  }
447  public static Vector2D[] Reduce(Vector2D[] vertexes, Scalar areaTolerance)
448  {
449  if (vertexes == null) { throw new ArgumentNullException("vertexes"); }
450  if (vertexes.Length < 2) { throw new ArgumentOutOfRangeException("vertexes"); }
451  if (areaTolerance < 0) { throw new ArgumentOutOfRangeException("areaTolerance", "must be equal to or greater then zero."); }
452  List<Vector2D> result = new List<Vector2D>(vertexes.Length);
453  Vector2D v1, v2, v3;
454  Scalar old1, old2, new1;
455  v1 = vertexes[vertexes.Length - 2];
456  v2 = vertexes[vertexes.Length - 1];
457  areaTolerance *= 2;
458  for (int index = 0; index < vertexes.Length; ++index, v2 = v3)
459  {
460  if (index == vertexes.Length - 1)
461  {
462  if (result.Count == 0) { throw new ArgumentOutOfRangeException("areaTolerance", "The Tolerance is too high!"); }
463  v3 = result[0];
464  }
465  else { v3 = vertexes[index]; }
466  Vector2D.ZCross(ref v1, ref v2, out old1);
467  Vector2D.ZCross(ref v2, ref v3, out old2);
468  Vector2D.ZCross(ref v1, ref v3, out new1);
469  if (Math.Abs(new1 - (old1 + old2)) > areaTolerance)
470  {
471  result.Add(v2);
472  v1 = v2;
473  }
474  }
475  return result.ToArray();
476  }
482  public static Scalar GetArea(Vector2D[] vertexes)
483  {
484  Scalar result;
485  BoundingPolygon.GetArea(vertexes, out result);
486  return result;
487  }
496  public static Vector2D GetCentroid(Vector2D[] vertexes)
497  {
498  Vector2D result;
499  BoundingPolygon.GetCentroid(vertexes, out result);
500  return result;
501  }
507  public static Vector2D[] CenterVertexes(Vector2D[] vertexes)
508  {
509  Vector2D centroid;
510  BoundingPolygon.GetCentroid(vertexes, out centroid);
511  return OperationHelper.ArrayRefOp<Vector2D, Vector2D, Vector2D>(vertexes, ref centroid, Vector2D.Subtract);
512  }
513 
514  public static Vector2D[][] GetIntersectionOfRange(Vector2D[][] polygons, Line line)
515  {
516  List<Vector2D[]> submerged = new List<Vector2D[]>(polygons.Length);
517  for (int index = 0; index < polygons.Length; ++index)
518  {
519  Vector2D[] vertexes = GetIntersection(polygons[index], line);
520  if (vertexes.Length >= 3) { submerged.Add(vertexes); }
521  }
522  return submerged.ToArray();
523  }
524  public static Scalar GetAreaOfRange(Vector2D[][] polygons)
525  {
526  if (polygons == null) { throw new ArgumentNullException("polygons"); }
527  if (polygons.Length == 0) { throw new ArgumentOutOfRangeException("polygons"); }
528  Scalar result = 0;
529  Scalar temp;
530  Vector2D[] polygon;
531  for (int index = 0; index < polygons.Length; ++index)
532  {
533  polygon = polygons[index];
534  if (polygon == null) { throw new ArgumentNullException("polygons"); }
535  BoundingPolygon.GetArea(polygon, out temp);
536  result += temp;
537  }
538  return result;
539  }
540  public static Vector2D GetCentroidOfRange(Vector2D[][] polygons)
541  {
542  if (polygons == null) { throw new ArgumentNullException("polygons"); }
543  if (polygons.Length == 0) { throw new ArgumentOutOfRangeException("polygons"); }
544 
545 
546  Scalar temp, area, areaTotal;
547  Vector2D v1, v2;
548  Vector2D[] vertexes;
549  areaTotal = 0;
550  Vector2D result = Vector2D.Zero;
551  for (int index1 = 0; index1 < polygons.Length; ++index1)
552  {
553  vertexes = polygons[index1];
554  if (vertexes == null) { throw new ArgumentNullException("polygons"); }
555  if (vertexes.Length < 3) { throw new ArgumentOutOfRangeException("polygons", "There must be at least 3 vertexes"); }
556  v1 = vertexes[vertexes.Length - 1];
557  area = 0;
558  for (int index = 0; index < vertexes.Length; ++index, v1 = v2)
559  {
560  v2 = vertexes[index];
561  Vector2D.ZCross(ref v1, ref v2, out temp);
562  area += temp;
563  result.X += ((v1.X + v2.X) * temp);
564  result.Y += ((v1.Y + v2.Y) * temp);
565  }
566  areaTotal += Math.Abs(area);
567  }
568  temp = 1 / (areaTotal * 3);
569  result.X *= temp;
570  result.Y *= temp;
571  return result;
572  }
573  public static Vector2D[][] CenterVertexesRange(Vector2D[][] polygons)
574  {
575  if (polygons == null) { throw new ArgumentNullException("polygons"); }
576  Vector2D centroid = GetCentroidOfRange(polygons);
577  Vector2D[][] result = new Vector2D[polygons.Length][];
578  for (int index = 0; index < polygons.Length; ++index)
579  {
580  result[index] = OperationHelper.ArrayRefOp<Vector2D, Vector2D, Vector2D>(polygons[index], ref centroid, Vector2D.Subtract);
581  }
582  return result;
583  }
584  public static Vector2D[][] ReduceRange(Vector2D[][] polygons)
585  {
586  return ReduceRange(polygons, 0);
587  }
588  public static Vector2D[][] ReduceRange(Vector2D[][] polygons, Scalar areaTolerance)
589  {
590  if (polygons == null) { throw new ArgumentNullException("polygons"); }
591  Vector2D[][] result = new Vector2D[polygons.Length][];
592  for (int index = 0; index < polygons.Length; ++index)
593  {
594  result[index] = Reduce(polygons[index], areaTolerance);
595  }
596  return result;
597  }
598  public static Vector2D[][] SubdivideRange(Vector2D[][] polygons, Scalar maxLength)
599  {
600  return SubdivideRange(polygons, maxLength, true);
601  }
602  public static Vector2D[][] SubdivideRange(Vector2D[][] polygons, Scalar maxLength, bool loop)
603  {
604  if (polygons == null) { throw new ArgumentNullException("polygons"); }
605  Vector2D[][] result = new Vector2D[polygons.Length][];
606  for (int index = 0; index < polygons.Length; ++index)
607  {
608  result[index] = Subdivide(polygons[index], maxLength, loop);
609  }
610  return result;
611  }
612 
613  }
614 }
Jypeli.Physics2d.VertexHelper.GetArea
static Scalar GetArea(Vector2D[] vertexes)
Calculates the area of a polygon.
Definition: VertexHelper.cs:482
Jypeli.Physics2d.BitmapHelper.CreateFromBitmap
static Vector2D[] CreateFromBitmap(IBitmap bitmap)
Definition: BitmapHelper.cs:194
Jypeli.Physics2d.VertexInfo.Area
Scalar Area
Definition: VertexHelper.cs:61
Jypeli.Physics2d.VertexHelper.Subdivide
static Vector2D[] Subdivide(Vector2D[] vertexes, Scalar maxLength)
makes sure the distance between 2 vertexes is under the length passed, by adding vertexes between the...
Definition: VertexHelper.cs:380
Jypeli.Physics2d.IBitmap.Width
int Width
Definition: BitmapHelper.cs:42
Jypeli.Physics2d.BitmapHelper
Definition: BitmapHelper.cs:74
Jypeli.Physics2d.VertexHelper.SubdivideRange
static Vector2D[][] SubdivideRange(Vector2D[][] polygons, Scalar maxLength, bool loop)
Definition: VertexHelper.cs:602
Jypeli.Physics2d.VertexInfo.area
Scalar area
Definition: VertexHelper.cs:45
AdvanceMath.Vector2D.Subtract
static Vector2D Subtract(Vector2D left, Vector2D right)
Subtracts 2 Vector2Ds.
Definition: Vector2D.cs:306
Jypeli.Physics2d.BitmapHelper.CreateManyFromBitmap
static Vector2D[][] CreateManyFromBitmap(IBitmap bitmap)
Definition: BitmapHelper.cs:198
AdvanceMath.Matrix2x3
A 2x3 matrix which can represent rotations around axes.
Definition: Matrix2x3.cs:62
Jypeli.Physics2d.VertexHelper.ReduceRange
static Vector2D[][] ReduceRange(Vector2D[][] polygons)
Definition: VertexHelper.cs:584
AdvanceMath.Vector2D.ZCross
static Scalar ZCross(Vector2D left, Vector2D right)
Does a "2D" Cross Product also know as an Outer Product.
Definition: Vector2D.cs:471
AdvanceMath.Vector2D.Magnitude
Scalar Magnitude
Gets or Sets the Magnitude (Length) of the Vector2D.
Definition: Vector2D.cs:890
Jypeli.Physics2d.VertexHelper.GetAreaOfRange
static Scalar GetAreaOfRange(Vector2D[][] polygons)
Definition: VertexHelper.cs:524
AdvanceMath.MathHelper
Definition: MathHelper.cs:38
AdvanceMath.Vector2D.Add
static Vector2D Add(Vector2D left, Vector2D right)
Adds 2 Vectors2Ds.
Definition: Vector2D.cs:287
Jypeli.Physics2d.VertexHelper.Subdivide
static Vector2D[] Subdivide(Vector2D[] vertexes, Scalar maxLength, bool loop)
makes sure the distance between 2 vertexes is under the length passed, by adding vertexes between the...
Definition: VertexHelper.cs:391
AdvanceMath.Vector2D.Normalize
static Vector2D Normalize(Vector2D source)
This returns the Normalized Vector2D that is passed. This is also known as a Unit Vector.
Definition: Vector2D.cs:615
Jypeli.Physics2d.VertexHelper.CenterVertexes
static Vector2D[] CenterVertexes(Vector2D[] vertexes)
repositions the polygon so the Centroid is the origin.
Definition: VertexHelper.cs:507
AdvanceMath.OperationHelper
Definition: OperationHelper.cs:42
Jypeli.Physics2d.VertexHelper.GetVertexNormalsOfRange
static Vector2D[][] GetVertexNormalsOfRange(Vector2D[][] polygons)
Definition: VertexHelper.cs:328
Jypeli.Physics2d.VertexHelper.GetVertexInfoOfRange
static VertexInfo GetVertexInfoOfRange(Vector2D[][] polygons)
Definition: VertexHelper.cs:255
Jypeli.Physics2d.VertexHelper.GetInertiaOfRange
static Scalar GetInertiaOfRange(Vector2D[][] polygons)
Definition: VertexHelper.cs:154
AdvanceMath.Vector2D.Zero
static readonly Vector2D Zero
Vector2D(0,0)
Definition: Vector2D.cs:69
AdvanceMath.Geometry2D.Line
Definition: Line.cs:44
Jypeli.Physics2d.VertexInfo.VertexInfo
VertexInfo(Vector2D centroid, Scalar inertia, Scalar area)
Definition: VertexHelper.cs:46
AdvanceMath.Geometry2D.BoundingPolygon.GetInertia
static Scalar GetInertia(Vector2D[] vertexes)
Definition: BoundingPolygon.cs:292
AdvanceMath.Geometry2D.BoundingPolygon.GetCentroid
static Vector2D GetCentroid(Vector2D[] vertexes)
Calculates the Centroid of a polygon.
Definition: BoundingPolygon.cs:202
Jypeli.Physics2d.VertexHelper.GetIntersectionOfRange
static Vector2D[][] GetIntersectionOfRange(Vector2D[][] polygons, Line line)
Definition: VertexHelper.cs:514
Jypeli.Physics2d.VertexHelper.ApplyMatrix
static Vector2D[] ApplyMatrix(ref Matrix2x3 matrix, Vector2D[] vertexes)
Definition: VertexHelper.cs:68
AdvanceMath.Geometry2D.BoundingPolygon.GetArea
static Scalar GetArea(Vector2D[] vertexes)
Calculates the area of a polygon.
Definition: BoundingPolygon.cs:242
Jypeli.Physics2d.VertexInfo.inertia
Scalar inertia
Definition: VertexHelper.cs:44
Jypeli.Physics2d.VertexHelper.GetIntersection
static Vector2D[] GetIntersection(Vector2D[] vertexes, Scalar radius)
INCOMPLETE! TODO: FINISH
Definition: VertexHelper.cs:191
AdvanceMath.Geometry2D.Line.GetDistance
Scalar GetDistance(Vector2D point)
Definition: Line.cs:108
Jypeli.Physics2d.VertexHelper.CreateRangeFromBitmap
static Vector2D[][] CreateRangeFromBitmap(bool[,] bitmap)
Definition: VertexHelper.cs:102
AdvanceMath.Geometry2D
Definition: BoundingCircle.cs:36
Jypeli.Physics2d.VertexHelper.ReduceRange
static Vector2D[][] ReduceRange(Vector2D[][] polygons, Scalar areaTolerance)
Definition: VertexHelper.cs:588
Jypeli.Physics2d
Definition: BitmapHelper.cs:39
Jypeli.Physics2d.IBitmap.Height
int Height
Definition: BitmapHelper.cs:43
Jypeli.Physics2d.VertexHelper.ApplyMatrixToRange
static Vector2D[][] ApplyMatrixToRange(ref Matrix2x3 matrix, Vector2D[][] polygons)
Definition: VertexHelper.cs:72
Jypeli.Physics2d.VertexHelper.CreateRectangle
static Vector2D[] CreateRectangle(Scalar width, Scalar height)
creates vertexes that describe a Rectangle.
Definition: VertexHelper.cs:118
Jypeli.Physics2d.VertexInfo.Centroid
Vector2D Centroid
Definition: VertexHelper.cs:53
Jypeli.Physics2d.VertexHelper.GetIntersection
static Vector2D[] GetIntersection(Vector2D[] vertexes, Line line)
Definition: VertexHelper.cs:341
AdvanceMath.Vector2D.X
Scalar X
This is the X value. (Usually represents a horizontal position or direction.)
Definition: Vector2D.cs:796
AdvanceMath.Vector2D.Multiply
static Vector2D Multiply(Vector2D source, Scalar scalar)
Does Scaler Multiplication on a Vector2D.
Definition: Vector2D.cs:413
Jypeli.Physics2d.VertexInfo
Definition: VertexHelper.cs:42
Jypeli.Physics2d.VertexHelper.SubdivideRange
static Vector2D[][] SubdivideRange(Vector2D[][] polygons, Scalar maxLength)
Definition: VertexHelper.cs:598
Jypeli.Physics2d.VertexHelper.GetCentroid
static Vector2D GetCentroid(Vector2D[] vertexes)
Calculates the Centroid of a polygon.
Definition: VertexHelper.cs:496
Jypeli.Physics2d.VertexHelper
Definition: VertexHelper.cs:67
AdvanceMath.Vector2D.Dot
static Scalar Dot(Vector2D left, Vector2D right)
Does a Dot Operation Also know as an Inner Product.
Definition: Vector2D.cs:445
Scalar
System.Single Scalar
Definition: Clamped.cs:29
AdvanceMath.Vector2D.Transform
static Vector2D Transform(Matrix3x3 matrix, Vector2D source)
Uses a matrix multiplication to Transform the vector.
Definition: Vector2D.cs:325
AdvanceMath.Vector2D.FromLengthAndAngle
static Vector2D FromLengthAndAngle(Scalar length, Scalar radianAngle)
Creates a Vector2D With the given length (Magnitude) and the given Angle.
Definition: Vector2D.cs:206
Jypeli.Physics2d.VertexHelper.Reduce
static Vector2D[] Reduce(Vector2D[] vertexes)
Reduces a Polygon's number of vertexes.
Definition: VertexHelper.cs:434
AdvanceMath.Vector2D.GetRightHandNormal
static Vector2D GetRightHandNormal(Vector2D source)
Gets a Vector2D that is perpendicular(orthogonal) to the passed Vector2D while staying on the XY Plan...
Definition: Vector2D.cs:693
Jypeli.Physics2d.VertexHelper.Reduce
static Vector2D[] Reduce(Vector2D[] vertexes, Scalar areaTolerance)
Reduces a Polygon's number of vertexes.
Definition: VertexHelper.cs:447
Jypeli.Physics2d.VertexInfo.Inertia
Scalar Inertia
Definition: VertexHelper.cs:57
Jypeli.Physics2d.VertexHelper.GetVertexInfo
static VertexInfo GetVertexInfo(Vector2D[] vertexes)
Definition: VertexHelper.cs:224
System
Definition: CFFauxAttributes.cs:29
Jypeli.Physics2d.VertexHelper.CalculateNormals
static void CalculateNormals(Vector2D[] vertexes, Vector2D[] normals, int offset)
Definition: VertexHelper.cs:298
Jypeli.Physics2d.VertexInfo.centroid
Vector2D centroid
Definition: VertexHelper.cs:43
AdvanceMath.Vector2D.ToArray
Scalar[] ToArray()
Definition: Vector2D.cs:948
Jypeli.Physics2d.VertexHelper.GetInertia
static Scalar GetInertia(Vector2D[] vertexes)
Calculates the moment of inertia for a polygon
Definition: VertexHelper.cs:150
Jypeli.Physics2d.IBitmap
Definition: BitmapHelper.cs:41
AdvanceMath.Geometry2D.BoundingPolygon
Definition: BoundingPolygon.cs:39
AdvanceMath.Vector2D.CopyTo
void CopyTo(Scalar[] array, int index)
Definition: Vector2D.cs:958
Jypeli.Physics2d.VertexHelper.CreateFromBitmap
static Vector2D[] CreateFromBitmap(IBitmap bitmap)
Definition: VertexHelper.cs:96
Jypeli.Physics2d.VertexHelper.CreateFromBitmap
static Vector2D[] CreateFromBitmap(bool[,] bitmap)
Takes a 2D Boolean array with a true value representing a collidable pixel and converts it to an arra...
Definition: VertexHelper.cs:92
Jypeli.Physics2d.VertexHelper.CenterVertexesRange
static Vector2D[][] CenterVertexesRange(Vector2D[][] polygons)
Definition: VertexHelper.cs:573
Jypeli.Physics2d.VertexHelper.GetCentroidOfRange
static Vector2D GetCentroidOfRange(Vector2D[][] polygons)
Definition: VertexHelper.cs:540
AdvanceMath.Vector2D
This is the Vector Class.
Definition: Vector2D.cs:50
Jypeli.Physics2d.ArrayBitmap
Definition: BitmapHelper.cs:47
AdvanceMath.Vector2D.Y
Scalar Y
This is the Y value. (Usually represents a vertical position or direction.)
Definition: Vector2D.cs:805
Jypeli.Physics2d.VertexHelper.CreateCircle
static Vector2D[] CreateCircle(Scalar radius, int vertexCount)
Definition: VertexHelper.cs:132
AdvanceMath
Definition: Clamped.cs:36
Jypeli.Physics2d.VertexHelper.GetVertexNormals
static Vector2D[] GetVertexNormals(Vector2D[] vertexes)
Definition: VertexHelper.cs:321
AdvanceMath.Vector2D.Lerp
static Vector2D Lerp(Vector2D left, Vector2D right, Scalar amount)
Definition: Vector2D.cs:141
Jypeli.Physics2d.VertexHelper.CreateRangeFromBitmap
static Vector2D[][] CreateRangeFromBitmap(IBitmap bitmap)
Definition: VertexHelper.cs:106
AdvanceMath.MathHelper.TwoPi
const Scalar TwoPi
Definition: MathHelper.cs:42