//Is a triangle oriented clockwise private void IsTriangleOrientedClockwise(MyVector2 a, MyVector2 b, MyVector2 c) { Triangle2 t = new Triangle2(a, b, c); bool isOrientedClockwise = _Geometry.IsTriangleOrientedClockwise(t.p1, t.p2, t.p3); Debug.Log("Is oriented clockwise: " + isOrientedClockwise); //We can also test if changing orientation is working t.ChangeOrientation(); bool isOrientedClockwiseAfterRotation = _Geometry.IsTriangleOrientedClockwise(t.p1, t.p2, t.p3); Debug.Log("Is oriented clockwise after changing orientation: " + isOrientedClockwiseAfterRotation); //Display the triangle Gizmos.color = Color.white; Gizmos.DrawLine(a.ToVector3(), b.ToVector3()); Gizmos.DrawLine(b.ToVector3(), c.ToVector3()); Gizmos.DrawLine(c.ToVector3(), a.ToVector3()); //Arrows showing the direction of the triangle float arrowSize = 0.1f; TestAlgorithmsHelpMethods.DisplayArrow(a.ToVector3(), b.ToVector3(), arrowSize, Color.white); TestAlgorithmsHelpMethods.DisplayArrow(b.ToVector3(), c.ToVector3(), arrowSize, Color.white); TestAlgorithmsHelpMethods.DisplayArrow(c.ToVector3(), a.ToVector3(), arrowSize, Color.white); }
private void PointInRelationToPlane(MyVector2 a, MyVector2 b, MyVector2 testPoint) { MyVector2 planeDir = b - a; MyVector2 planeNormal = MyVector2.Normalize(new MyVector2(planeDir.y, -planeDir.x)); MyVector2 planePos = a + planeDir * 0.5f; //Positive if infront, negative if behind float distanceToPlane = _Geometry.DistanceFromPointToPlane(planeNormal, planePos, testPoint); Debug.Log("Distance: " + distanceToPlane); //Display //Plane Gizmos.color = Color.blue; Gizmos.DrawLine(a.ToVector3(), b.ToVector3()); //Plane normal Gizmos.DrawLine(planePos.ToVector3(), planePos.ToVector3() + planeNormal.ToVector3() * 0.1f); //Point Gizmos.color = Color.white; Gizmos.DrawWireSphere(testPoint.ToVector3(), 0.1f); }
private void CenterOfCircle(MyVector2 a, MyVector2 b, MyVector2 c) { MyVector2 center = _Geometry.CalculateCircleCenter(a, b, c); //MyVector2 center = _Geometry.CalculateCircleCenter_Alternative2(a, b, c); //Debug.Log(center.x + " " + center.y); float radius = Vector3.Magnitude(a.ToVector3() - center.ToVector3()); Gizmos.DrawWireSphere(center.ToVector3(), radius); }
//Is a quadtrilateral convex private void IsQuadrilateralConvex(MyVector2 a, MyVector2 b, MyVector2 c, MyVector2 d) { bool isConvex = _Geometry.IsQuadrilateralConvex(a, b, c, d); Debug.Log("Is convex " + isConvex); //Display the quadrilateral Gizmos.color = Color.white; Gizmos.DrawLine(a.ToVector3(), b.ToVector3()); Gizmos.DrawLine(b.ToVector3(), c.ToVector3()); Gizmos.DrawLine(c.ToVector3(), d.ToVector3()); Gizmos.DrawLine(d.ToVector3(), a.ToVector3()); }
//Is a point to the left or to the right of a vector going from a to b private void PointInRelationToVector(MyVector2 a, MyVector2 b, MyVector2 p) { //bool isToLeft = Geometry.IsPointLeftOfVector(a, b, p); //Debug.Log("Is to left: " + isToLeft); LeftOnRight value = _Geometry.IsPoint_Left_On_Right_OfVector(a, b, p); if (value == LeftOnRight.Left) { Debug.Log("Left"); } if (value == LeftOnRight.On) { Debug.Log("On"); } if (value == LeftOnRight.Right) { Debug.Log("Right"); } //Display Vector3 a_3d = a.ToVector3(); Vector3 b_3d = b.ToVector3(); Gizmos.DrawLine(a_3d, b_3d); float arrowSize = 0.1f; TestAlgorithmsHelpMethods.DisplayArrow(a_3d, b_3d, arrowSize, Color.white); Gizmos.DrawWireSphere(p.ToVector3(), 0.1f); }
//TestAlgorithmsHelpMethods.DisplayMeshWithRandomColors(displayMesh, seed); //Is adding memory each time we run it in playmode, which could maybe //have been solved by destroying the meshes we create each update??? //But DrawMesh is similar private void OnDrawGizmos() { if (multiColoredMeshes != null) { foreach (Mesh m in multiColoredMeshes) { TestAlgorithmsHelpMethods.DisplayMeshEdges(m, Color.black); } } //This point is set to be outside if its not active Gizmos.color = Color.white; Gizmos.DrawWireSphere(activePoint.ToVector3(), 0.3f); //Connected points if (connectedPoints != null) { Gizmos.color = Color.white; for (int i = 0; i < connectedPoints.Count; i++) { //Show the circle Gizmos.DrawWireSphere(connectedPoints[i].ToVector3(), 0.2f); //Line to previous point if (i > 0) { Gizmos.DrawLine(connectedPoints[i].ToVector3(), connectedPoints[i - 1].ToVector3()); } } } }
private void PassedWaypoint(MyVector2 wp1, MyVector2 wp2, MyVector2 testPoint) { bool hasPassed = _Geometry.HasPassedWaypoint(wp1, wp2, testPoint); Debug.Log(hasPassed); //Diplay TestAlgorithmsHelpMethods.DisplayArrow(wp1.ToVector3(), wp2.ToVector3(), 0.5f, Color.white); Gizmos.color = hasPassed ? Color.red : Color.black; Gizmos.DrawWireSphere(testPoint.ToVector3(), 0.5f); }
private void IsPointBetweenPoints(MyVector2 a, MyVector2 b, MyVector2 testPoint) { bool isBetween = _Geometry.IsPointBetweenPoints(a, b, testPoint); Debug.Log("Is between: " + isBetween); //Diplay Gizmos.color = Color.white; Gizmos.DrawLine(a.ToVector3(), b.ToVector3()); Gizmos.DrawWireSphere(testPoint.ToVector3(), 0.1f); }
//TestAlgorithmsHelpMethods.DisplayMeshWithRandomColors(displayMesh, seed); //Is adding memory each time we run it in playmode, which could maybe //have been solved by destroying the meshes we create each update??? //But DrawMesh is similar private void OnDrawGizmos() { if (triangleMeshes != null) { foreach (Mesh m in triangleMeshes) { TestAlgorithmsHelpMethods.DisplayMeshEdges(m, Color.black); } Gizmos.color = Color.white; Gizmos.DrawWireSphere(activePoint.ToVector3(), 0.3f); } }
private void ClosestPointOnLineSegment(MyVector2 a, MyVector2 b, MyVector2 testPoint) { MyVector2 closestPoint = Geometry.GetClosestPointOnLineSegment(a, b, testPoint); //Diplay Gizmos.color = Color.white; Gizmos.DrawLine(a.ToVector3(), b.ToVector3()); Gizmos.DrawWireSphere(testPoint.ToVector3(), 0.1f); Gizmos.color = Color.red; Gizmos.DrawWireSphere(closestPoint.ToVector3(), 0.1f); }
//Display a plane public static void DrawPlane(MyVector2 planePos_2d, MyVector2 planeNormal, Color color) { Vector3 planeDir = new Vector3(planeNormal.y, 0f, -planeNormal.x); Vector3 planePos = planePos_2d.ToVector3(); //Draw the plane which is just a long line float infinite = 100f; Gizmos.color = color; Gizmos.DrawRay(planePos, planeDir * infinite); Gizmos.DrawRay(planePos, -planeDir * infinite); //Draw the plane normal Gizmos.DrawLine(planePos, planePos + planeNormal.ToVector3() * 1f); }