Jypeli 10
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
28using Scalar = System.Double;
29#else
30using Scalar = System.Single;
31#endif
32using System;
33using System.Collections.Generic;
34using AdvanceMath;
36
37
38namespace 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 }
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}
System.Single Scalar
Definition: Clamped.cs:29
static Scalar GetInertia(Vector2D[] vertexes)
static Vector2D GetCentroid(Vector2D[] vertexes)
Calculates the Centroid of a polygon.
static Scalar GetArea(Vector2D[] vertexes)
Calculates the area of a polygon.
const Scalar TwoPi
Definition: MathHelper.cs:42
static Vector2D[] CreateFromBitmap(IBitmap bitmap)
static Vector2D[][] CreateManyFromBitmap(IBitmap bitmap)
static Vector2D[][] CenterVertexesRange(Vector2D[][] polygons)
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...
static VertexInfo GetVertexInfoOfRange(Vector2D[][] polygons)
static Vector2D[][] ReduceRange(Vector2D[][] polygons)
static void CalculateNormals(Vector2D[] vertexes, Vector2D[] normals, int offset)
static Vector2D[] GetIntersection(Vector2D[] vertexes, Line line)
static Vector2D[] CreateRectangle(Scalar width, Scalar height)
creates vertexes that describe a Rectangle.
static Scalar GetInertia(Vector2D[] vertexes)
Calculates the moment of inertia for a polygon
static Vector2D[] Subdivide(Vector2D[] vertexes, Scalar maxLength)
makes sure the distance between 2 vertexes is under the length passed, by adding vertexes between the...
static Vector2D[][] ReduceRange(Vector2D[][] polygons, Scalar areaTolerance)
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
static Vector2D[][] GetVertexNormalsOfRange(Vector2D[][] polygons)
static Scalar GetArea(Vector2D[] vertexes)
Calculates the area of a polygon.
static Vector2D GetCentroid(Vector2D[] vertexes)
Calculates the Centroid of a polygon.
static Scalar GetAreaOfRange(Vector2D[][] polygons)
static Vector2D[] CreateFromBitmap(IBitmap bitmap)
Definition: VertexHelper.cs:96
static Vector2D[][] ApplyMatrixToRange(ref Matrix2x3 matrix, Vector2D[][] polygons)
Definition: VertexHelper.cs:72
static Vector2D[] GetIntersection(Vector2D[] vertexes, Scalar radius)
INCOMPLETE! TODO: FINISH
static VertexInfo GetVertexInfo(Vector2D[] vertexes)
static Scalar GetInertiaOfRange(Vector2D[][] polygons)
static Vector2D[] Reduce(Vector2D[] vertexes, Scalar areaTolerance)
Reduces a Polygon's number of vertexes.
static Vector2D[] CenterVertexes(Vector2D[] vertexes)
repositions the polygon so the Centroid is the origin.
static Vector2D[] ApplyMatrix(ref Matrix2x3 matrix, Vector2D[] vertexes)
Definition: VertexHelper.cs:68
static Vector2D[] Reduce(Vector2D[] vertexes)
Reduces a Polygon's number of vertexes.
static Vector2D[] CreateCircle(Scalar radius, int vertexCount)
static Vector2D[][] SubdivideRange(Vector2D[][] polygons, Scalar maxLength, bool loop)
static Vector2D[][] CreateRangeFromBitmap(IBitmap bitmap)
static Vector2D[] GetVertexNormals(Vector2D[] vertexes)
static Vector2D[][] CreateRangeFromBitmap(bool[,] bitmap)
static Vector2D[][] SubdivideRange(Vector2D[][] polygons, Scalar maxLength)
static Vector2D[][] GetIntersectionOfRange(Vector2D[][] polygons, Line line)
static Vector2D GetCentroidOfRange(Vector2D[][] polygons)
VertexInfo(Vector2D centroid, Scalar inertia, Scalar area)
Definition: VertexHelper.cs:46
Scalar GetDistance(Vector2D point)
Definition: Line.cs:108
A 2x3 matrix which can represent rotations around axes.
Definition: Matrix2x3.cs:62
This is the Vector Class.
Definition: Vector2D.cs:50
static readonly Vector2D Zero
Vector2D(0,0)
Definition: Vector2D.cs:69
static Vector2D Add(Vector2D left, Vector2D right)
Adds 2 Vectors2Ds.
Definition: Vector2D.cs:287
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
static Vector2D Multiply(Vector2D source, Scalar scalar)
Does Scaler Multiplication on a Vector2D.
Definition: Vector2D.cs:413
Scalar Magnitude
Gets or Sets the Magnitude (Length) of the Vector2D.
Definition: Vector2D.cs:890
Scalar X
This is the X value. (Usually represents a horizontal position or direction.)
Definition: Vector2D.cs:796
static Vector2D Transform(Matrix3x3 matrix, Vector2D source)
Uses a matrix multiplication to Transform the vector.
Definition: Vector2D.cs:325
void CopyTo(Scalar[] array, int index)
Definition: Vector2D.cs:958
Scalar[] ToArray()
Definition: Vector2D.cs:948
static Scalar Dot(Vector2D left, Vector2D right)
Does a Dot Operation Also know as an Inner Product.
Definition: Vector2D.cs:445
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
static Vector2D FromLengthAndAngle(Scalar length, Scalar radianAngle)
Creates a Vector2D With the given length (Magnitude) and the given Angle.
Definition: Vector2D.cs:206
static Vector2D Subtract(Vector2D left, Vector2D right)
Subtracts 2 Vector2Ds.
Definition: Vector2D.cs:306
Scalar Y
This is the Y value. (Usually represents a vertical position or direction.)
Definition: Vector2D.cs:805
static Scalar ZCross(Vector2D left, Vector2D right)
Does a "2D" Cross Product also know as an Outer Product.
Definition: Vector2D.cs:471
static Vector2D Lerp(Vector2D left, Vector2D right, Scalar amount)
Definition: Vector2D.cs:141