private void Input() { mousePos = (Vector2f)Mouse.GetPosition(mWindow); if (Mouse.IsButtonPressed(0) && mCurrentSelected == null) { foreach (CircleZone zone in mCircleZones) { if (zone.PointInZone(mousePos)) { mCurrentSelected = zone; } } } else if (Mouse.IsButtonPressed(0) && mCurrentSelected != null) { // mCurrentSelected.MoveTo(mousePos); Node selectedNode = mSimulator.GetNode(mCurrentSelected.GetNodeIdx()); Vector2f direction = mousePos - selectedNode.mNewPosition; mSimulator.GetNode(mCurrentSelected.GetNodeIdx()).mForces = direction; } else { mCurrentSelected = null; } }
public Intersection GetIntersections(CircleZone other) { Vector2f direction = other.mPosition - mPosition; float distanceAway = MathUtil.Length(direction); // Both Circles are to far away from ech other - no intersections if (distanceAway > mRadius + other.mRadius) { return(null); } // No intersection because one circle is contained within the other. if (distanceAway < Math.Abs(mRadius - other.mRadius)) { return(null); } // coincident - infinite number of solutions. if (Math.Abs(distanceAway) < 0.001f && Math.Abs(mRadius - other.mRadius) < 0.001f) { return(null); } // Calculation based on // https://stackoverflow.com/questions/3349125/circle-circle-intersection-points // TODOO: Optimization double r0_squ = Math.Pow(mRadius, 2); double r1_squ = Math.Pow(other.mRadius, 2); double d_squ = Math.Pow(distanceAway, 2); Vector2f p0 = mPosition; float a = (float)(r0_squ - r1_squ + d_squ) / (2 * distanceAway); float h = (float)Math.Sqrt(r0_squ - Math.Pow(a, 2)); Vector2f p2 = p0 + a * MathUtil.Normalize(direction); float p3_0_x = p2.X + h * (other.mPosition.Y - mPosition.Y) / distanceAway; float p3_0_y = p2.Y - h * (other.mPosition.X - mPosition.X) / distanceAway; float p3_1_x = p2.X - h * (other.mPosition.Y - mPosition.Y) / distanceAway; float p3_1_y = p2.Y + h * (other.mPosition.X - mPosition.X) / distanceAway; Vector2f p3_0 = new Vector2f(p3_0_x, p3_0_y); Vector2f p3_1 = new Vector2f(p3_1_x, p3_1_y); Intersection intersection = new Intersection(p3_0, p3_1); intersection.mZoneA = this; intersection.mZoneB = other; return(intersection); }
public Intersection GetMiddleOfIntersection(CircleZone other) { Vector2f direction = other.mPosition - mPosition; float distanceAway = MathUtil.Length(direction); // Both Circles are to far away from ech other - no intersections if (distanceAway > mRadius + other.mRadius) { return(null); } // No intersection because one circle is contained within the other. if (distanceAway < Math.Abs(mRadius - other.mRadius)) { return(null); } // coincident - infinite number of solutions. if (Math.Abs(distanceAway) < 0.001f && Math.Abs(mRadius - other.mRadius) < 0.001f) { return(null); } // Calculation based on // https://stackoverflow.com/questions/3349125/circle-circle-intersection-points // TODOO: Optimization double r0_squ = Math.Pow(mRadius, 2); double r1_squ = Math.Pow(other.mRadius, 2); double d_squ = Math.Pow(distanceAway, 2); Vector2f p0 = mPosition; float a = (float)(r0_squ - r1_squ + d_squ) / (2 * distanceAway); Vector2f p2 = p0 + a * MathUtil.Normalize(direction); return(new Intersection(p2, p2)); }
public TriangleMidpoint(CircleZone circleZone0, CircleZone circleZone1, CircleZone circleZone2) { mCircleZone0 = circleZone0; mCircleZone1 = circleZone1; mCircleZone2 = circleZone2; }