public MovementNode(Vector2D position, double facingAngle, double desiredSpeed, Vector2D goal, int depth) { position_ = position; facingAngle_ = facingAngle; desiredSpeed_ = desiredSpeed; goal_ = goal; distanceToGoal_ = Vector2D.Distance(position_, goal_); bestBranchDistanceToGoal_ = distanceToGoal_; depth_ = depth; children_ = new List <MovementNode>(); markedForDeletion_ = false; GeneratedChildren = false; }
// This splits this line by vertex v // Returns the new line resulting from the split, or null when it failed public Linedef Split(Vertex v) { // Copy linedef and change vertices Linedef nl = map.CreateLinedef(v, end); if (nl == null) { return(null); } CopyPropertiesTo(nl); SetEndVertex(v); nl.Selected = this.Selected; nl.marked = this.marked; // Copy front wall if exists if (front != null) { Sidedef nsd = map.CreateSidedef(nl, true, front.Sector); if (nsd == null) { return(null); } front.CopyPropertiesTo(nsd); nsd.Marked = front.Marked; // Make texture offset adjustments //TODO: works differently in Build... nsd.OffsetX += (int)Vector2D.Distance(this.start.Position, this.end.Position); } // Copy back wall if exists if (back != null) { Sidedef nsd = map.CreateSidedef(nl, false, back.Sector); if (nsd == null) { return(null); } back.CopyPropertiesTo(nsd); nsd.Marked = back.Marked; // Make texture offset adjustments //TODO: works differently in Build... back.OffsetX += (int)Vector2D.Distance(nl.start.Position, nl.end.Position); } // Return result General.Map.IsChanged = true; return(nl); }
public override State NextState() { this.updateDTO(); double distDone = Vector2D.Distance(this.sp.posActual, this.sp.posInicial); if (distDone < this.sp.distance) { return(new Forward2(this.sp)); } else { return(new Stop(new StateDTO(this.sp.posActual, this.sp.dirInicial, this.sp.distance, this.sp.posActual, this.sp.dirActual))); } }
public Highlight CheckHighlight(Vector2D pos, double scale) { double distance = double.MaxValue; double d; Highlight highlight = Highlight.None; // Find a line to highlight foreach (Highlight h in (Highlight[])Enum.GetValues(typeof(Highlight))) { if (h >= Highlight.OuterLeft && h <= Highlight.OuterBottom) { d = Line2D.GetDistanceToLine(lines[h].v1, lines[h].v2, pos, true); if (d <= BuilderModes.BuilderPlug.Me.HighlightRange / scale && d < distance) { distance = d; highlight = h; } } } distance = double.MaxValue; // Find a corner to highlight foreach (Highlight h in (Highlight[])Enum.GetValues(typeof(Highlight))) { if (h >= Highlight.OuterTopLeft && h <= Highlight.OuterBottomRight) { d = Vector2D.Distance(pos, points[h]); if (d <= BuilderModes.BuilderPlug.Me.HighlightRange / scale && d < distance) { distance = d; highlight = h; } } } if (highlight != Highlight.None) { return(highlight); } if (OuterLeft < pos.x && OuterRight > pos.x && OuterTop > pos.y && OuterBottom < pos.y) { return(Highlight.Body); } return(Highlight.None); }
static public Slice2D SliceFromOutsideToHole(Polygon2D polygon, Polygon2D holePoly, List <Vector2D> slice, Collision collisionSlice) { Slice2D result = Slice2D.Create(null, slice); Polygon2D polyA = new Polygon2D(); Polygon2D polyB = new Polygon2D(holePoly.pointsList); polyB.pointsList.Reverse(); List <Vector2D> pointsA = Vector2DList.GetListStartingIntersectSlice(polygon.pointsList, slice); List <Vector2D> pointsB = Vector2DList.GetListStartingIntersectSlice(polyB.pointsList, slice); if (pointsA.Count < 1) { Debug.LogWarning("Slicer2D: Not enough of slice intersections with polygon (SliceWithOneHole)"); } polyA.AddPoints(pointsA); // pointsA empty if (collisionSlice.GetPointsInside().Count > 0) { if (Vector2D.Distance(pointsA.Last(), collisionSlice.Last()) < Vector2D.Distance(pointsA.Last(), collisionSlice.First())) { collisionSlice.Reverse(); } polyA.AddPoints(collisionSlice.GetPointsInside()); } polyA.AddPoints(pointsB); if (collisionSlice.GetPointsInside().Count > 0) { collisionSlice.Reverse(); polyA.AddPoints(collisionSlice.GetPointsInside()); } foreach (Polygon2D poly in polygon.holesList) // Check for errors? { if (poly != holePoly && polyA.PolyInPoly(poly) == true) { polyA.AddHole(poly); } } result.AddPolygon(polyA); return(result); }
//------------ Helper_AddAllNeighboursToGridNode ------------------ // // use to add the eight neighboring edges of a graph node that // are positioned in a grid layout //------------------------------------------------------------------------ public static void Helper_AddAllNeighboursToGridNode(SparseGraph graph, int row, int col, int NumCellsX, int NumCellsY) { for (int i = -1; i < 2; ++i) { for (int j = -1; j < 2; ++j) { int nodeX = col + j; int nodeY = row + i; //skip if equal to this node if ((i == 0) && (j == 0)) { continue; } //check to see if this is a valid neighbour if (ValidNeighbour(nodeX, nodeY, NumCellsX, NumCellsY)) { //calculate the distance to this node Vector2D PosNode = graph.GetNode(row * NumCellsX + col).Pos; Vector2D PosNeighbour = graph.GetNode(nodeY * NumCellsX + nodeX).Pos; double dist = PosNode.Distance(PosNeighbour); NavGraphEdge NewEdge; //this neighbour is okay so it can be added NewEdge = new NavGraphEdge(row * NumCellsX + col, nodeY * NumCellsX + nodeX, dist); graph.AddEdge(NewEdge); //if graph is not a diagraph then an edge needs to be added going //in the other direction if (!graph.isDigraph()) { NewEdge = new NavGraphEdge(nodeY * NumCellsX + nodeX, row * NumCellsX + col, dist); graph.AddEdge(NewEdge); } } } } }
public List <Vector2D> GetList() { List <Vector2D> list = new List <Vector2D>(pointsList); if (list.Count > 0) { Vector2D pos = new Vector2D(input.GetInputPosition()); if (Vector2D.Distance(list.Last(), pos) > 0.01f) { list.Add(pos); } } return(list); }
/// <summary> /// 捕获圆形上的点 /// </summary> /// <param name="v"></param> /// <returns></returns> public override IntersectPoint IntersectPoint(Vector2D v) { if (Math.Abs(v.Distance(this.Start) - this.Radius) < KernelProperty.PixelToSize) { Line2D l = Line2D.Create(this.Start, v); Vector2D nv = this.Start.Offset(this.Radius, l.Direction); IntersectPoint ip = new IntersectPoint(); ip.IntersectPointStyle = 1; ip.Line = l; ip.Point = nv; return(ip); } return(null); }
public Vector2D FindNearestLanePos(Vector2D Pos) { float MinDis = float.MaxValue; int MinDisIndex = 0; for (int i = 0; i < LeftLane.Count; i++) { if (Vector2D.Distance(Pos, Cell.GetVector2D(LeftLane[i])) < MinDis) { MinDis = Vector2D.Distance(Pos, Cell.GetVector2D(LeftLane[i])); MinDisIndex = i; } } return(Cell.GetVector2D(LeftLane[MinDisIndex])); }
public override State NextState() { this.updateDTO(); double distDone = Vector2D.Distance(this.sp.posActual, this.sp.posInicial); Screen.AddText("Distance done: ", distDone.ToString()); if (distDone < this.sp.distance) { return(new Forward(this.sp)); } else { return(new Turn(new StateDTO(this.sp.posActual, this.sp.dirActual, this.sp.distance, this.sp.posActual, this.sp.dirActual))); } }
public void Update(Vector2D pos) { float scroll = Input.GetAxis("Mouse ScrollWheel"); float newCutSize = cutSize + scroll; if (newCutSize > 0.05f) { cutSize = newCutSize; } if (input.GetInputClicked()) { pointsList.Clear(); pointsList.Add(pos); } if (pointsList.Count < 1) { return; } if (input.GetInputHolding()) { Vector2D posMove = pointsList.Last().Copy(); int loopCount = 0; while ((Vector2D.Distance(posMove, pos) > minVertexDistance * visuals.visualScale)) { float direction = (float)Vector2D.Atan2(pos, posMove); posMove.Push(direction, minVertexDistance * visuals.visualScale); pointsList.Add(posMove.Copy()); loopCount++; if (loopCount > 150) { break; } } } if (input.GetInputReleased()) { ComplexCut complexCutLine = ComplexCut.Create(GetList(), cutSize * visuals.visualScale); Slicer2D.ComplexCutSliceAll(complexCutLine, sliceLayer); pointsList.Clear(); } }
public void FindCorrelation(int x2, int y2, Transition Transitor, ref Bitmap bit) { using (Graphics g = Graphics.FromImage(bit)) { double lowt = CacllowT(); Vector2D vp = new Vector2D(Transitor.RealX(x2), Transitor.RealY(y2)); Vector2D v0 = new Vector2D(X(CacllowT()), Y(CacllowT())); Vector2D vt1 = new Vector2D(); Vector2D vt2 = new Vector2D(); double t2 = 0; double koef = 0; double step = (CacltopT() - CacllowT()) / FragmentationDepth; for (double t = CacllowT() + step; t <= CacltopT(); t = t + step) { Vector2D v1 = new Vector2D(X(t), Y(t)); double disv0v1 = Vector2D.Distance(v0, v1); double disvv0 = Vector2D.Distance(vp, v0); double disvv1 = Vector2D.Distance(vp, v1); if (disv0v1 / (disvv0 + disvv1) > koef) { koef = disv0v1 / (disvv0 + disvv1); vt1 = v0; vt2 = v1; t2 = t; } //if (Math.Abs(km-kd)<0.15&&(Math.Sign(y1 - y0)== Math.Sign(y - y0))&& (Math.Sign(x1 - x0) == Math.Sign(x - x0))) //{ // double tm = t + step*(y - y0) / (y1 - y0); // if(y<0 && y > -10) // { // g.DrawString("t = " + tm.ToString(), new Font(new FontFamily("Arial"), 8), new SolidBrush(GraphColor) , x2, y2 - 5); // } // else // g.DrawString("t = " + tm.ToString(), new Font(new FontFamily("Arial"), 8), new SolidBrush(GraphColor), x2, y2 + 5); // break; //} v0 = v1; } if (koef > 0.5) { double ts = t2 - step * (Vector2D.Distance(vp, vt2) / Vector2D.Distance(vt1, vt2)); g.DrawString("t = " + (t2 - step * (Vector2D.Distance(vp, vt2) / Vector2D.Distance(vt1, vt2))).ToString(), new Font("Arial", 8, FontStyle.Italic), new SolidBrush(GraphColor), x2, y2 - 15); g.DrawString("y = " + Transitor.RealY(y2).ToString(), new Font("Arial", 8, FontStyle.Italic), new SolidBrush(GraphColor), x2, y2 - 25); g.DrawString("x = " + Transitor.RealX(x2).ToString(), new Font("Arial", 8, FontStyle.Italic), new SolidBrush(GraphColor), x2, y2 - 35); } } }
public static Mesh TriangulateAdvanced(Polygon2D polygon, Vector2 UVScale, Vector2 UVOffset) { foreach (Pair2D p in Pair2D.GetList(new List <Vector2D>(polygon.pointsList))) { if (polygon.pointsList.Count < 4) { break; } if (Vector2D.Distance(p.A, p.B) < 0.005f) { Debug.LogWarning("Slicer2D: Polygon points are too close"); polygon.pointsList.Remove(p.A); } } TriangulationWrapper.Polygon poly = new TriangulationWrapper.Polygon(); List <Vector2> pointsList = null; List <Vector2> UVpointsList = null; Vector3 v = Vector3.zero; foreach (Vector2D p in polygon.pointsList) { v = p.ToVector2(); poly.outside.Add(v); poly.outsideUVs.Add(new Vector2(v.x / UVScale.x + .5f + UVOffset.x, v.y / UVScale.y + .5f + UVOffset.y)); } foreach (Polygon2D hole in polygon.holesList) { pointsList = new List <Vector2> (); UVpointsList = new List <Vector2> (); foreach (Vector2D p in hole.pointsList) { v = p.ToVector2(); pointsList.Add(v); UVpointsList.Add(new Vector2(v.x / UVScale.x + .5f, v.y / UVScale.y + .5f)); } poly.holes.Add(pointsList); poly.holesUVs.Add(UVpointsList); } return(TriangulationWrapper.CreateMesh(poly)); }
void Start() { Vector2D position = new Vector2D(anchorBody.transform.position); material = MaterialManager.GetSpriteCopy().material; texture = Resources.Load("Sprites/Rope/SmallRope") as Texture; material.mainTexture = texture; GameObject prev = anchorBody; int ropeId = 1; GameObject gObject = null; float distance = 1.5f; while (Vector2D.Distance(position, new Vector2D(connectedBody.transform.position)) > distance) { double direction = Vector2D.Atan2(new Vector2D(connectedBody.transform.position), position); gObject = new GameObject(); HingeJoint2D hingeJoint = gObject.AddComponent <HingeJoint2D>(); hingeJoint.connectedBody = prev.GetComponent <Rigidbody2D>(); gObject.transform.parent = transform; gObject.transform.position = position.ToVector2(); gObject.name = "Rope " + ropeId; //gObject.AddComponent<JointRenderer2D> ().color = color; gObject.AddComponent <CircleCollider2D> ().radius = .25f; nodes.Add(hingeJoint); position.Push(direction, distance); prev = gObject; ropeId++; } if (gameObject != null) { HingeJoint2D joint = gObject.AddComponent <HingeJoint2D>(); joint.connectedBody = connectedBody.GetComponent <Rigidbody2D>(); nodes.Add(joint); } }
public void Move() { List <PhysicsBody> toDestroy = new List <PhysicsBody> (); foreach (PhysicsBody pb in Simulation.AllBodies) { if (pb != this) { if (Vector2D.Distance(this.Position, pb.Position) <= (this.Radius + pb.Radius)) { if (this.Mass < pb.Mass) { pb.Position += this.Velocity; pb.Mass += this.Mass; pb.Velocity += this.Mass * this.Velocity / pb.Mass; toDestroy.Add(this); break; } } Vector2D vAccel = ((pb.Position - this.Position) / Vector2D.Distance(pb.Position, this.Position)) * Globals.Acceleration(pb.Mass, Vector2D.Distance(this.Position, pb.Position)); this.Velocity += vAccel; } } if (toDestroy.Count > 0) { if (toDestroy.Contains(this)) { Destroy(this); } else { Destroy(toDestroy[0]); this.Position += this.Velocity; } } else { this.Position += this.Velocity; } foreach (PhysicsBody pb in toDestroy) { Console.WriteLine($"Destroyed {pb.ID.ToString ()}"); } Console.WriteLine(this.ToString()); toDestroy.Clear(); }
/// <summary> /// 判断是否需要进入争球 /// </summary> /// <param name="newBallPos"></param> /// <returns></returns> public bool IsInFree(Vector2D newBallPos) { //test for limitcapacity //int test = 0; //int testCap = Capacity; //if (BallPosQueue.Count < Capacity) // return false; //foreach (var pos in BallPosQueue) //{ // testpos[--testCap] = pos; //} //for (int i = 0; i < Capacity; i++) //{ // if (Vector2D.Distance(testpos[i], newBallPos) > LimitMove) // { // return false; // } // test++; // if (test == 3* Const.FramePerSecond) // { // Time.timeScale = 0; // } //} ////此时判罚是进入争球,进行清空 //BallPosQueue.Clear(); //return true; //real code if (BallPosQueue.Count < Capacity) { return(false); } foreach (var pos in BallPosQueue) { if (Vector2D.Distance(pos, newBallPos) > LimitMove) { return(false); } } //此时判罚是进入争球,进行清空 BallPosQueue.Clear(); return(true); }
public void Update(Vector2D pos) { float scroll = Input.GetAxis("Mouse ScrollWheel"); float newCutSize = cutSize + scroll; if (newCutSize > 0.05f) { cutSize = newCutSize; } if (Input.GetMouseButtonDown(0)) { complexSlicerPointsList.Clear(); complexSlicerPointsList.Add(pos); mouseDown = true; } if (complexSlicerPointsList.Count < 1) { return; } if (Input.GetMouseButton(0)) { Vector2D posMove = new Vector2D(complexSlicerPointsList.Last()); while ((Vector2D.Distance(posMove, pos) > visuals.minVertexDistance * visuals.visualScale)) { float direction = (float)Vector2D.Atan2(pos, posMove); posMove.Push(direction, visuals.minVertexDistance * visuals.visualScale); complexSlicerPointsList.Add(new Vector2D(posMove)); } } if (mouseDown == true && Input.GetMouseButton(0) == false) { mouseDown = false; Destruction2D.DestroyByComplexCutAll(complexCutLine, destructionLayer); complexSlicerPointsList.Clear(); } }
// http://stackoverflow.com/a/1501725/420250 public static double LineSegmentPointDistance(Vector2D v, Vector2D w, Vector2D p) { // Return minimum distance between line segment vw and point p double l2 = (v - w).sqrMagnitude; // i.e. |w-v|^2 - avoid a sqrt if (l2 == 0.0) { return(Vector2D.Distance(p, v)); // v == w case } // Consider the line extending the segment, parameterized as v + t (w - v). // We find projection of point p onto the line. // It falls where t = [(p-v) . (w-v)] / |w-v|^2 // We clamp t from [0,1] to handle points outside the segment vw. double t = System.Math.Max(0.0, System.Math.Min(1.0, Vector2D.Dot(p - v, w - v) / l2)); Vector2D projection = v + t * (w - v); // Projection falls on the segment return(Vector2D.Distance(p, projection)); }
public Vector2D Arrive() { Vector2D ToTarget = TargetPos - movingEntity.Pos; float slowingradius = 100f; double dist = TargetPos.Distance(movingEntity.Pos); float speed = movingEntity.MaxSpeed; if (dist < slowingradius) { speed = movingEntity.MaxSpeed * (float)(dist / slowingradius); } Vector2D DesiredVelocity = Vector2D.Vec2DNormalize(ToTarget) * movingEntity.MaxSpeed; movingEntity.arriveSpeed = speed; return(DesiredVelocity - movingEntity.Velocity); }
public Polygon2D ToRotation(float rotation, Vector2D center = null) { Polygon2D newPolygon = new Polygon2D(); if (center == null) { center = new Vector2D(Vector2.zero); } foreach (Vector2D pos in pointsList) { float dist = (float)Vector2D.Distance(pos, center); float rot = (float)Vector2D.Atan2(pos, center) + rotation; newPolygon.AddPoint((float)center.x + Mathf.Cos(rot) * dist, (float)center.y + Mathf.Sin(rot) * dist); } return(newPolygon); }
static private void ShadowForObject(Polygon2 polygon, Vector2 position) { Vector2[] pointsList = polygon.points; int pointsCount = pointsList.Length; Light2D light = ShadowEngine.light; SoftShadowSorter.Set(polygon, light); pair.A.x = SoftShadowSorter.minPoint.x + position.x; pair.A.y = SoftShadowSorter.minPoint.y + position.y; pair.B.x = SoftShadowSorter.maxPoint.x + position.x; pair.B.y = SoftShadowSorter.maxPoint.y + position.y; Pair2D edge_world = pair; Vector2 edgePosition; edgePosition.x = (float)(pair.A.x + pair.B.x) / 2; edgePosition.y = (float)(pair.A.y + pair.B.y) / 2; float edgeRotation = (float)Math.Atan2(pair.B.y - pair.A.y, pair.B.x - pair.A.x); float edgeSize = (float)Vector2D.Distance(pair.A, pair.B) / 2; pass.edgePosition = edgePosition; pass.edgeRotation = edgeRotation; pass.edgeSize = edgeSize; pass.coreSize = light.coreSize; pass.Generate(); pass.SetVars(); pass.Draw(); pass.edgePosition = edgePosition; pass.edgeRotation = edgeRotation + Mathf.PI; pass.edgeSize = edgeSize; pass.coreSize = light.coreSize; pass.Generate(); pass.SetVars(); pass.Draw(); }
// Checking mouse press and release events to get linear slices based on input public void LateUpdate() { for (int id = 0; id < 10; id++) { Vector2D pos = new Vector2D(input.GetInputPosition(id)); if (input.GetInputClicked(id)) { points[id].Clear(); points[id].Add(pos); } if (input.GetInputPressed(id)) { Vector2D posMove = new Vector2D(points[id].Last()); while ((Vector2D.Distance(posMove, pos) > minVertexDistance)) { float direction = (float)Vector2D.Atan2(pos, posMove); posMove.Push(direction, minVertexDistance); points[id].Add(new Vector2D(posMove)); } } if (input.GetInputReleased(id)) { Slicer2D.complexSliceType = complexSliceType; if (input.GetSlicingEnabled(id)) { ComplexSlice(points[id]); } points[id].Clear(); } if (input.GetInputPressed(id) == false) { if (points[id].Count > 0) { points[id].Clear(); } } } }
private void UpdateComplexCut(Vector2D pos) { if (Input.GetMouseButtonDown(0)) { pointsList.Clear(); pointsList.Add(pos); mouseDown = true; } if (pointsList.Count < 1) { return; } if (Input.GetMouseButton(0)) { Vector2D posMove = pointsList.Last().Copy(); int loopCount = 0; while ((Vector2D.Distance(posMove, pos) > minVertexDistance * visualScale)) { float direction = (float)Vector2D.Atan2(pos, posMove); posMove.Push(direction, minVertexDistance * visualScale); pointsList.Add(posMove.Copy()); loopCount++; if (loopCount > 150) { break; } } } if (mouseDown == true && Input.GetMouseButton(0) == false) { ComplexCut complexCutLine = ComplexCut.Create(pointsList, cutSize * visualScale); Slicer2D.ComplexCutSliceAll(complexCutLine, sliceLayer); pointsList.Clear(); mouseDown = false; } }
static public List <Pair2D> GetSplitSlices(Polygon2D polygon, Pair2D slice) { // Getting the list of intersections List <Pair2D> slices = new List <Pair2D>(); List <Vector2D> intersections = polygon.GetListLineIntersectPoly(slice); // Single collision cannot make a proper slice if (intersections.Count < 2) { return(slices); } // Sorting intersections from one point intersections = Vector2DList.GetListSortedToPoint(intersections, slice.A); // Dividing intersections into single slices // Optimize this (polygon.PointInPoly) line // This method doesn't look like very reliable!!! foreach (Pair2D p in Pair2D.GetList(intersections, false)) { Vector2D midPoint = new Vector2D((p.B.x + p.A.x) / 2, (p.B.y + p.A.y) / 2); if (Vector2D.Distance(p.A, p.B) < 0.001f) { continue; } if (polygon.PointInPoly(midPoint) == false) { continue; } slices.Add(p); intersections.Remove(p.A); intersections.Remove(p.B); } return(slices); }
public void Update(Vector2D pos) { if (input.GetInputClicked()) { pointsList.Clear(); complexTracker.trackerList.Clear(); pointsList.Add(pos); } if (input.GetInputPressed() && pointsList.Count > 0) { Vector2D posMove = pointsList.Last().Copy(); int loopCount = 0; while ((Vector2D.Distance(posMove, pos) > minVertexDistance)) { float direction = (float)Vector2D.Atan2(pos, posMove); posMove.Push(direction, minVertexDistance); Slicer2D.complexSliceType = complexSliceType; pointsList.Add(posMove.Copy()); complexTracker.Update(posMove.ToVector2(), 0); loopCount++; if (loopCount > 150) { break; } } complexTracker.Update(posMove.ToVector2(), minVertexDistance); } if (input.GetInputReleased()) { pointsList.Clear(); complexTracker.trackerList.Clear(); } }
public static void GetPerimeter(Vector2D[] vertexes, out Scalar result) { if (vertexes == null) { throw new ArgumentNullException("vertexes"); } if (vertexes.Length < 3) { throw new ArgumentOutOfRangeException("vertexes", "There must be at least 3 vertexes"); } Vector2D v1 = vertexes[vertexes.Length - 1]; Vector2D v2; Scalar dist; result = 0; for (int index = 0; index < vertexes.Length; ++index, v1 = v2) { v2 = vertexes[index]; Vector2D.Distance(ref v1, ref v2, out dist); result += dist; } }
public void Update(Vector2D pos, Transform transform) { float newPolygonSize = polygonSize + Input.GetAxis("Mouse ScrollWheel"); if (newPolygonSize > 0.05f) { polygonSize = newPolygonSize; } if (input.GetInputClicked()) { pointsList.Clear(); pointsList.Add(pos); } if (createType == CreateType.Slice) { if (input.GetInputHolding()) { if (pointsList.Count == 0 || (Vector2D.Distance(pos, pointsList.Last()) > minVertexDistance * visuals.visualScale)) { pointsList.Add(pos); } } if (input.GetInputReleased()) { CreatorSlice(pointsList, transform); } } else { if (input.GetInputClicked()) { PolygonCreator(pos, transform); } } }
private void UpdateComplexTracked(Vector2D pos) { if (Input.GetMouseButtonDown(0)) { pointsList.Clear(); complexTracker.trackerList.Clear(); pointsList.Add(pos); } if (Input.GetMouseButton(0) && pointsList.Count > 0) { Vector2D posMove = pointsList.Last().Copy(); int loopCount = 0; while ((Vector2D.Distance(posMove, pos) > minVertexDistance)) { float direction = (float)Vector2D.Atan2(pos, posMove); posMove.Push(direction, minVertexDistance); Slicer2D.complexSliceType = complexSliceType; pointsList.Add(posMove.Copy()); complexTracker.Update(posMove.ToVector2(), 0); loopCount++; if (loopCount > 150) { break; } } mouseDown = true; complexTracker.Update(posMove.ToVector2(), minVertexDistance); } else { mouseDown = false; } }
public List <Vector2D> GetPointsInsidePlus() { List <Vector2D> points = GetPointsInside(); points.Insert(0, inside.A); points.Add(inside.B); Vector2D lastPoint = null; foreach (Vector2D point in new List <Vector2D>(points)) { if (lastPoint != null) { if (Vector2D.Distance(point, lastPoint) < 0.01f) { points.Remove(lastPoint); } } lastPoint = point; } return(points); }
//this returns an array of linedef lengths relative to total segment length private float[] GetRelativeLengths(Vector2D[] pointGroup) { float[] relLenGroup = new float[pointGroup.Length]; relLenGroup[0] = 0.0f; //get length and angle of line, which defines the shape float length = Vector2D.Distance(pointGroup[0], pointGroup[segmentsCount - 1]); float angle = (float)Math.Atan2(pointGroup[0].y - pointGroup[segmentsCount - 1].y, pointGroup[0].x - pointGroup[segmentsCount - 1].x); //get relative length of every line for (int i = 1; i < pointGroup.Length - 1; i++) { Vector2D p0 = pointGroup[i - 1]; Vector2D p1 = pointGroup[i]; float curAngle = (float)Math.Atan2(p0.y - p1.y, p0.x - p1.x); float diff = (angle + Angle2D.PI) - (curAngle + Angle2D.PI); float segLen = (int)(Vector2D.Distance(p0, p1) * Math.Cos(diff)); relLenGroup[i] = relLenGroup[i - 1] + segLen / length; } relLenGroup[pointGroup.Length - 1] = 1.0f; return(relLenGroup); }
/* Print out a force vector that will move the given pusher to the given target location. */ public static void MoveTo(Pusher p, Vector2D target) { // Compute a frame with axis a1 pointing at the target. Vector2D a1, a2; // Build a frame (a trivial one if we're already too close). double dist = target.Distance(p.pos); if (dist < 0.0001) { a1 = new Vector2D(1.0, 0.0); a2 = new Vector2D(0.0, 1.0); } else { a1 = (target - p.pos) * (1.0 / dist); a2 = a1.Perp(); } // Represent the pusher velocity WRT that frame. double v1 = a1 * p.vel; double v2 = a2 * p.vel; // Compute a force vector in this frame, first cancel out velocity // perp to the target. double f1 = 0; double f2 = -v2; // If we have remaining force to spend, use it to move toward the target. if (Math.Abs(f2) < PUSHER_ACCEL_LIMIT) { double raccel = Math.Sqrt(PUSHER_ACCEL_LIMIT * PUSHER_ACCEL_LIMIT - v2 * v2); f1 = GoalUtility.MoveTo(-dist, v1, 0.0, raccel); } // Convert force Vector2D force = a1 * f1 + a2 * f2; p.MoveThisTurn = force.x + " " + force.y; }