10 static void Get2DPolygon(notnull array<vector> points3D, out notnull array<float> points2D)
13 if (points3D.IsEmpty())
16 foreach (vector point3D : points3D)
18 points2D.Insert(point3D[0]);
19 points2D.Insert(point3D[2]);
29 static void Get3DPolygon(notnull array<float> points2D, out notnull array<vector> points3D)
31 int count = points2D.Count();
37 for (
int i; i < count; i += 2)
39 points3D.Insert({ points2D[i], 0, points2D[i + 1] });
46 static bool GetMinMaxPolygon(notnull array<float> polygon, out
float minX, out
float maxX, out
float minY, out
float maxY)
48 if (!IsPolygonValid(polygon))
57 for (
int i = 2, count = polygon.Count(); i < count; i += 2)
79 static float GetPolygonArea(notnull array<float> polygon)
81 if (!IsPolygonValid(polygon))
87 for (
int i = 0, count = polygon.Count(); i < count; i += 2)
90 result += 0.5 * (polygon[i] * polygon[j + 1] - polygon[j] * polygon[i + 1]);
108 static bool GetRandomPointInPolygon(notnull array<float> polygon, out
float x, out
float y)
110 float minX, minY, maxX, maxY;
111 if (!GetMinMaxPolygon(polygon, minX, maxX, minY, maxY))
114 GetRandomPointInRectangle(minX, maxX, minY, maxY, x, y);
115 while (!Math2D.IsPointInPolygon(polygon, x, y))
117 GetRandomPointInRectangle(minX, maxX, minY, maxY, x, y);
126 static bool GetRandomPointInRectangle(
float minX,
float maxX,
float minY,
float maxY, out
float x, out
float y)
128 x = Math.RandomFloat(minX, maxX);
129 y = Math.RandomFloat(minY, maxY);
137 static bool GetRandomPointInSector(
float originX,
float originY,
float angleFrom,
float angleTo,
float radius, out
float x, out
float y)
139 float distance = radius * Math.Sqrt(Math.RandomFloat01());
140 float angle = Math.RandomFloat(angleFrom,angleTo);
141 x = originX +
distance * Math.Cos(angle);
142 y = originY +
distance * Math.Sin(angle);
148 static bool IsPolygonValid(notnull array<float> polygon)
150 int count = polygon.Count();
196 static bool PolarToCartesian(
float angle,
float radius, out
float x, out
float y)
198 x = Math.Cos(angle) * radius;
199 y = Math.Sin(angle) * radius;
343 static vector GenerateRandomPoint(array<float> polygon, vector bbMin, vector bbMax)
345 return SCR_Math.GetMathRandomGenerator().GenerateRandomPoint(polygon, bbMin, bbMax);
357 static vector GenerateRandomPointInRadius(
float minRadius,
float maxRadius, vector center,
bool uniform =
true)
359 return SCR_Math.GetMathRandomGenerator().GenerateRandomPointInRadius(minRadius, maxRadius, center, uniform);