/// <summary> /// Finds a random point within the spherical annulus by drawing a /// vector whose magnitude is between `r` and `2r` at a random angle. /// </summary> /// <param name="origin">donut center</param> /// <returns>random sample</returns> private Vertex getRandomPointAround(Vertex origin) { float magnitude = Random.Range(minDistance, maxDistance); float angle = Random.Range(0f, 360f); return(new Vertex(Mathy.getEndpointOfLineRotation(origin.x, origin.y, angle, magnitude))); }
static void Main(string[] args) { Mathy m = new Mathy(); Console.WriteLine(m.Add(2, 4)); Console.WriteLine(m.Add2(10, 100, 1000)); Console.ReadLine(); }
public void testGetAngleOfRotation90Deg() { double x1 = 0; double y1 = 0; double x2 = 0; double y2 = 5; float result = (float)Mathy.getAngleOfRotation(x1, y1, x2, y2) * Mathf.Rad2Deg; Assert.AreEqual(90.0f, result); }
public void testGetEndpointOfLineRotationQuadrant4Unsigned() { double theta = 315.0 * Mathf.Deg2Rad; double x = 0; double y = 0; float distance = 5; double[] result = Mathy.getEndpointOfLineRotation(x, y, theta, distance); // Check separately due to floating point precision, within 5 points Assert.AreEqual(5.0, result[0], 5); Assert.AreEqual(-5.0, result[1], 5); }
public void testGetAngleOfRotationInQuadrant4() { double x1 = 0; double y1 = 0; double x2 = 5; double y2 = -5; float result = (float)Mathy.getAngleOfRotation(x1, y1, x2, y2) * Mathf.Rad2Deg; Assert.GreaterOrEqual(result, -90); Assert.LessOrEqual(result, 0); Assert.AreEqual(-45.0f, result); }
public void testFindIntersectionParallel() { float ax = 0; float ay = 0; float bx = 5; float by = 0; float cx = 0; float cy = 5; float dx = 5; float dy = 5; double[] result = Mathy.findIntersection(ax, ay, bx, by, cx, cy, dx, dy); Assert.IsNull(result); }
public void testFindIntersectionNotOnLineSegments() { float ax = -5; float ay = -5; float bx = -1; float by = -1; float cx = 0; float cy = 0; float dx = 5; float dy = -5; double[] result = Mathy.findIntersection(ax, ay, bx, by, cx, cy, dx, dy); Assert.IsNull(result); }
public void testFindIntersectionCross() { // Q3 -> Q1 across origin float ax = -5; float ay = -5; float bx = 5; float by = 5; // Q2 -> Q4 across origin float cx = -5; float cy = 5; float dx = 5; float dy = -5; double[] result = Mathy.findIntersection(ax, ay, bx, by, cx, cy, dx, dy); Assert.IsNotNull(result); Assert.AreEqual(new double[] { 0, 0 }, result); }