private void SetClosestPoint(List <CirclePoint> points, out bool isEmptyBelow, out bool isEmptyAbove) { isEmptyAbove = true; float topPoint = transform.position.y + (transform.localScale.y / 2); float bottomPoint = transform.position.y - (transform.localScale.y / 2); closestPoint = new CirclePoint(new Vector3(), 10000); foreach (var obj in points.GetRange(180, 180)) { if (obj.Degree <= 180) { continue; } var result = Mathf.Abs(transform.position.x - obj.Vector3.x); if (result <= closestPoint.Distance) { closestPoint = new CirclePoint(obj.Vector3, result); var index = obj.Degree == 0 ? 0 : obj.Degree == 180 ? 180 : 360 - obj.Degree; if (topPoint > points[index].Vector3.y) { closestPointAbove = new CirclePoint(new Vector3(transform.position.x, points[index].Vector3.y)); closestPointAboveTopPoint = new CirclePoint(new Vector3(transform.position.x, topPoint)); isEmptyAbove = false; } } } isEmptyBelow = !(closestPoint.Vector3.y <= bottomPoint); }
public static double DistanceBetweenCircle(CirclePoint point1, CirclePoint point2) { var a = point1.X - point2.X; var b = point1.Y - point2.Y; var distance = Math.Sqrt(Math.Pow(a, 2) + Math.Pow(b, 2)); return(distance); }
public static bool WithinCircleBounds( Point2D pointLoc, int pointQuadrant, Point3D center, CirclePoint start, CirclePoint end, bool opposite ) { if (start.Angle == 0 && end.Angle == 360) { return(true); } var startX = start.Point.X; var startY = start.Point.Y; var endX = end.Point.X; var endY = end.Point.Y; var x = pointLoc.X; var y = pointLoc.Y; if (pointQuadrant < start.Quadrant || pointQuadrant > end.Quadrant) { return(opposite); } if (pointQuadrant > start.Quadrant && pointQuadrant < end.Quadrant) { return(!opposite); } var withinBounds = true; if (start.Quadrant == end.Quadrant) { if (startX == endX && (x > startX || y > startY || y < endY)) { withinBounds = false; } else if (startY == endY && (y < startY || x < startX || x > endX)) { withinBounds = false; } else if (x < startX || x > endX || y > startY || y < endY) { withinBounds = false; } } else if (pointQuadrant == start.Quadrant && (x < startX || y > startY)) { withinBounds = false; } else if (pointQuadrant == end.Quadrant && (x > endX || y < endY)) { withinBounds = false; } return(opposite ? !withinBounds : withinBounds); }
public static void Circle2D(Point3D loc, Map map, int radius, DoEffect_Callback effect, int angleStart, int angleEnd) { if (angleStart < 0 || angleStart > 360) { angleStart = 0; } if (angleEnd > 360 || angleEnd < 0) { angleEnd = 360; } if (angleStart == angleEnd) { return; } bool opposite = angleStart > angleEnd; int startQuadrant = angleStart / 90; int endQuadrant = angleEnd / 90; Point2D start = ArcPoint(loc, radius, angleStart % 90); Point2D end = ArcPoint(loc, radius, angleEnd % 90); if (opposite) { Swap(ref start, ref end); Swap(ref startQuadrant, ref endQuadrant); } CirclePoint startPoint = new CirclePoint(start, angleStart, startQuadrant); CirclePoint endPoint = new CirclePoint(end, angleEnd, endQuadrant); int error = -radius; int x = radius; int y = 0; while (x > y) { plot4points(loc, map, x, y, startPoint, endPoint, effect, opposite); plot4points(loc, map, y, x, startPoint, endPoint, effect, opposite); error += y * 2 + 1; ++y; if (error >= 0) { --x; error -= x * 2; } } plot4points(loc, map, x, y, startPoint, endPoint, effect, opposite); }
public static CirclePoint ReadPoint() { var coords = Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); var point = new CirclePoint() { X = coords[0], Y = coords[1], Radius = coords[2] }; return(point); }
private bool IsPointNeighbour(CirclePoint current, CirclePoint point) { for (int i = 0; i < point.neighbourPoints.Length; i++) { if (current == null && point.neighbourPoints[i] == null) { return(false); } if (current == point.neighbourPoints[i]) { return(true); } } return(false); }
public static void Main() { var c1 = CirclePoint.ReadPoint(); var c2 = CirclePoint.ReadPoint(); var distanceBetweenCenter = CirclePoint.DistanceBetweenCircle(c1, c2); var distanceBetweenRadius = CirclePoint.RadiusSum(c1, c2); if (distanceBetweenCenter <= distanceBetweenRadius) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } }
public void CreateCircle() { gameObject.transform.localScale = new Vector3(GetCircleScale(radius) + 0.03F, GetCircleScale(radius) + 0.03F, 0); Destroy(GetComponent <PolygonCollider2D>()); gameObject.AddComponent <PolygonCollider2D>(); int firstActivePoint = Random.Range(0, 3); int numPointsToNext = numPoints / 2; int lastActivePoint = firstActivePoint + numPointsToNext; //Debug.Log(gameObject.name + ":[" + firstActivePoint + ":" + lastActivePoint + "]"); for (int i = 0; i < numPoints; i++) { //multiply 'i' by '1.0f' to ensure the result is a fraction float pointNum = (i * 1.0f) / numPoints; //angle along the unit circle for placing points float angle = pointNum * Mathf.PI * 2; float x = Mathf.Sin(angle) * radius; float y = Mathf.Cos(angle) * radius; pointPos = new Vector3(x, y) + gameObject.transform.position; //position for the point prefab var currentAngle = GetAngleToTarget(pointPos); //place the prefab at given position CirclePoint point = Instantiate(PointPrefab, pointPos, Quaternion.Euler(0, 0, currentAngle)); bool activeType = false; if (i == firstActivePoint || i == lastActivePoint) { activeType = true; } else { activeType = Random.value > 0.7; // RAndom active points 30% } point.Initialize(activeType); point.transform.parent = gameObject.transform; points.Add(point); } var cir = Instantiate(CircleSpriteObject, transform.position, Quaternion.identity); cir.transform.parent = gameObject.transform; CircleSpriteObject.transform.localScale = new Vector3(GetCircleScale(radius), GetCircleScale(radius), 0); }
/// <summary> /// Does <see cref="point1"/> and <see cref="point2"/> share a neighbor /// </summary> /// <param name="point1"></param> /// <param name="point2"></param> /// <returns></returns> private bool DoesPointsShareNeighbours(CirclePoint point1, CirclePoint point2) { for (int i = 0; i < point1.neighbourPoints.Length; i++) { for (int j = 0; j < point2.neighbourPoints.Length; j++) { if (point2.neighbourPoints[j] == null && point1.neighbourPoints[i] == null) { return(false); } if (point1.neighbourPoints[i] == point2.neighbourPoints[j]) { return(true); } } } return(false); }
public static void plot4points( Point3D loc, Map map, int x, int y, CirclePoint start, CirclePoint end, DoEffect_Callback effect, bool opposite ) { var pointA = new Point2D(loc.X - x, loc.Y - y); var pointB = new Point2D(loc.X - y, loc.Y - x); var quadrant = 2; if (x == 0 && start.Quadrant == 3) { quadrant = 3; } if (WithinCircleBounds(quadrant == 3 ? pointB : pointA, quadrant, loc, start, end, opposite)) { effect(new Point3D(loc.X + x, loc.Y + y, loc.Z), map); } quadrant = 3; if (y == 0 && start.Quadrant == 0) { quadrant = 0; } if (x != 0 && WithinCircleBounds(quadrant == 0 ? pointA : pointB, quadrant, loc, start, end, opposite)) { effect(new Point3D(loc.X - x, loc.Y + y, loc.Z), map); } if (y != 0 && WithinCircleBounds(pointB, 1, loc, start, end, opposite)) { effect(new Point3D(loc.X + x, loc.Y - y, loc.Z), map); } if (x != 0 && y != 0 && WithinCircleBounds(pointA, 0, loc, start, end, opposite)) { effect(new Point3D(loc.X - x, loc.Y - y, loc.Z), map); } }
private CirclePoint FindClosestEndpoint(CirclePoint current, CirclePoint currentNeighbor = null) { CirclePoint closestPoint = null; float closestPointDist = float.PositiveInfinity; foreach (CirclePoint circlePoint in verticesPoints) { if (!circlePoint.isEndPoint || circlePoint == current || circlePoint == currentNeighbor) { continue; } if (circlePoint.origin == current.origin) { continue; } //if (Vector2.Distance(current.origin, circlePoint.origin) > radius * 2) continue; if (currentNeighbor != null) { if (circlePoint.origin == currentNeighbor.origin) { continue; } } float dist = Vector2.Distance(current.point, circlePoint.point); if (!(dist < closestPointDist)) { continue; } closestPoint = circlePoint; closestPointDist = dist; } return(closestPoint); }
private void ConfigureEndpoint() { foreach (CirclePoint circlePoint in verticesPoints) { if (!circlePoint.isEndPoint) { continue; } if (circlePoint.neighbourPoints[0] == null) { CirclePoint closestPoint = FindOtherEndpoint(circlePoint); if (closestPoint == null) { continue; } circlePoint.neighbourPoints[0] = closestPoint; closestPoint.neighbourPoints[1] = circlePoint; } if (circlePoint.neighbourPoints[1] == null) { CirclePoint closestPoint = FindOtherEndpoint(circlePoint); if (closestPoint == null) { continue; } circlePoint.neighbourPoints[1] = closestPoint; closestPoint.neighbourPoints[0] = circlePoint; } } }
private void CreateDebugPoints(Vector2 pos, int currentCircle) { if (pointsPerCircle < Mathf.Epsilon) { return; } bool previusCircleDrawn = false; CirclePoint previusCircle = null; bool firstCirclePointDrawn = false; bool secondCirclePointDrawn = false; CirclePoint firstCirclePoint = new CirclePoint(); for (float j = 0; j < 359; j += (float)360 / pointsPerCircle) { Vector2 radiusPoint = Quaternion.AngleAxis(j, Vector3.forward) * (radius * radiusOffset * Vector3.up); if (!CheckIntersectionWithPoints(radiusPoint + pos, currentCircle)) { CirclePoint circlepoint = new CirclePoint(points[currentCircle], radiusPoint + pos); if (j == 0) { firstCirclePoint = circlepoint; firstCirclePointDrawn = true; } else if (Mathf.Approximately(j, 360 / pointsPerCircle)) { secondCirclePointDrawn = true; } if (j + 360 / pointsPerCircle > 359) { circlepoint.isEndPoint = !firstCirclePointDrawn; if (secondCirclePointDrawn) { firstCirclePoint.isEndPoint = false; } if (firstCirclePointDrawn) { firstCirclePoint.neighbourPoints[0] = circlepoint; circlepoint.neighbourPoints[1] = firstCirclePoint; } } if (!previusCircleDrawn) { circlepoint.isEndPoint = true; } else { previusCircle.neighbourPoints[1] = circlepoint; circlepoint.neighbourPoints[0] = previusCircle; } verticesPoints.Add(circlepoint); previusCircleDrawn = true; previusCircle = circlepoint; } else { if (j + 360 / pointsPerCircle > 359) { firstCirclePoint.isEndPoint = true; } if (previusCircleDrawn) { if (verticesPoints.Count > 0) { verticesPoints[verticesPoints.Count - 1].isEndPoint = true; } } previusCircle = null; previusCircleDrawn = false; } } }
private void GenerateMesh() { Vector3[] vertices = new Vector3[verticesPoints.Count * 2]; int[] triangles = new int[verticesPoints.Count * 6]; MeshRenderer meshRenderer; MeshFilter meshFilter; if (!(meshRenderer = GetComponent <MeshRenderer>())) { meshRenderer = gameObject.AddComponent <MeshRenderer>(); } if (!(meshFilter = GetComponent <MeshFilter>())) { meshFilter = gameObject.AddComponent <MeshFilter>(); } Mesh mesh = meshFilter.mesh; mesh.Clear(); for (int i = 0; i < verticesPoints.Count; i++) { CirclePoint circlepoint = verticesPoints[i]; Vector3 v1, v2, v3, v4; v1 = circlepoint.point; v2 = (Vector3)circlepoint.point + new Vector3(0, 0, -meshDepth); //v3 = circlepoint.neighbourPoints[0].point; //v4 = (Vector3) circlepoint.neighbourPoints[0].point + new Vector3(0, 0, -meshDepth); vertices[i * 2] = v1; vertices[i * 2 + 1] = v2; circlepoint.pointInVertexList = i * 2; } for (int i = 0; i < verticesPoints.Count; i++) { if (verticesPoints[i] == null) { continue; } if (verticesPoints[i].neighbourPoints[0] == null) { continue; } CirclePoint circlepoint = verticesPoints[i]; CirclePoint circlePointNeighbour = circlepoint.neighbourPoints[0]; //int[] tris = CreateQuad(i * 2, i * 2 + 1, i * 2 + 2, i * 2 + 3); int[] tris = CreateQuad(circlepoint.pointInVertexList, verticesPoints[i].pointInVertexList + 1, circlePointNeighbour.pointInVertexList, circlePointNeighbour.pointInVertexList + 1); for (int k = 0; k < tris.Length; k++) { triangles[i * 6 + k] = tris[k]; } } meshRenderer.material = wallInsideMaterial; mesh.vertices = vertices; mesh.triangles = triangles; mesh.RecalculateNormals(); }
private CirclePoint FindOtherEndpoint(CirclePoint current) { List <CirclePoint> savedPoints = new List <CirclePoint>(); CirclePoint closestPoint = null; float closestPointDist = float.PositiveInfinity; foreach (CirclePoint circlePoint in verticesPoints) { if (!circlePoint.isEndPoint) { continue; } if (circlePoint == current) { continue; } if (current.origin == circlePoint.origin) { continue; } float dist = Vector2.Distance(current.point, circlePoint.point); if (dist > distanceBetweenPointsOnCircle * 2) { continue; } if (DoesPointsShareNeighbours(current, circlePoint)) { continue; } if (IsPointNeighbour(current, circlePoint)) { continue; } if (Vector2.Distance(current.origin, circlePoint.origin) > radius * 2) { savedPoints.Add(circlePoint); continue; } if (!(dist < closestPointDist)) { continue; } closestPoint = circlePoint; closestPointDist = dist; } if (closestPoint != null) { return(closestPoint); } else { closestPoint = null; closestPointDist = float.PositiveInfinity; foreach (CirclePoint savedPoint in savedPoints) { float dist = Vector2.Distance(current.point, savedPoint.point); if (!(dist < closestPointDist)) { continue; } closestPoint = savedPoint; closestPointDist = dist; } return(closestPoint); } }
public static double RadiusSum(CirclePoint r1, CirclePoint r2) { var dist = r1.Radius + r2.Radius; return(dist); }