//private int lastRandX = 100; //private int lastRandY = 100; //Random tempRandom = new Random(); private async void Found(object sender, PenFoundEventArgs penPositionEventArgs) { //Bitmap redaction = (Bitmap)e.Frame.Bitmap.Clone(); PointFrame pointFrame = penPositionEventArgs.Frame; if (pointFrame != null) { penDrawingBuffer.Enqueue(pointFrame); } // draw points in buffer to image using (Graphics g = Graphics.FromImage(_bitmap)) { using (SolidBrush brush = new SolidBrush(Color.Black)) { Point previousPoint = Point.Empty; foreach (PointFrame f in penDrawingBuffer) { g.DrawEllipse(Pens.Green, f.Point.X - 3, f.Point.Y - 3, 3, 3); if (!previousPoint.IsEmpty && PointTools.CalculateDistance(previousPoint, f.Point) < 50) { g.DrawLine(Pens.Red, previousPoint, f.Point); } previousPoint = f.Point; } } g.Save(); this.calibrationPictureBox.Image = _bitmap; } }
public static bool IsRectangleInEllipse(int rectangleX, int rectangleY, int rectangleWidth, int rectangleHeight, int x, int y) { var relMiddleCenterX = rectangleWidth / 2f; var relMiddleCenterY = rectangleHeight / 2f; var absMiddleCenterX = rectangleX + relMiddleCenterX; var absMiddleCenterY = rectangleY + relMiddleCenterY; // return(PointTools.IsPointInEllipse(absMiddleCenterX, absMiddleCenterY, relMiddleCenterX, relMiddleCenterY, x, y)); }
/// <summary> 获取多边形点的序号 /// </summary> /// <param name="point">点</param> /// <returns>点序号</returns> public virtual int GetPolygonPointIndex(PointF point) { point = new PointF(point.X + this.X + this.BorderWidth, point.Y + this.Y + this.BorderWidth); var select = this.Polygon.Select((p, i) => new { Index = i, Point = p }).Where(p => PointTools.Distance(new PointF(p.Point.X, p.Point.Y), point) <= PolygonPointsRadius).OrderBy(p => PointTools.Distance(new PointF(p.Point.X, p.Point.Y), point)).FirstOrDefault(); if (select == null) { return(-1); } else { return(select.Index); } }
protected internal override bool ContainPoint(PointF p) { p = new PointF(p.X + this.X + this.BorderWidth, p.Y + this.Y + this.BorderWidth); return(PointTools.IsPointInPolygon(p, this.Polygon) || this.Polygon.Any(py => PointTools.Distance(py, p) < PolygonPointsRadius)); }
/// <summary> 多边形是否包含点 /// </summary> /// <param name="p">点</param> /// <returns>是否包含点</returns> protected bool PolygonContainPoint(PointF p) { p = new PointF(p.X + this.X + this.BorderWidth, p.Y + this.Y + this.BorderWidth); return(PointTools.IsPointInPolygon(p, this.PolygonBounds)); }
internal protected override bool ContainPoint(PointF p) { return(PointTools.Distance(p, new PointF(this.Width / 2, this.Height / 2)) < ThisRadius); }
private List <Node> DijkstraBFS(Node pFrom, Node pTo) { _todoList.Add(pFrom); bool done = false; while (_todoList.Count > 0 && done == false) { var currentNode = _todoList.First(); _todoList.Remove(currentNode); _doneList.Add(currentNode); _todoListDebug.Add(currentNode); _doneListDebug.Add(currentNode); if (currentNode == pTo) { done = true; } else { for (int i = 0; i < currentNode.connections.Count; i++) { var connectedNode = currentNode.connections[i]; if (connectedNode.enabled && !(_todoList.Contains(connectedNode) || _doneList.Contains(connectedNode))) { float distanceFromStart = PointTools.PointDistance(currentNode.location, _startNode.location); float distanceToNew = PointTools.PointDistance(connectedNode.location, currentNode.location); connectedNode.distanceCost = distanceFromStart + distanceToNew; } else { connectedNode.distanceCost = -1; } } var sortedConnections = currentNode.connections.Where(n => n.distanceCost > 0).OrderBy(n => n.distanceCost); foreach (var sortedConnection in sortedConnections) { var connectedNode = sortedConnection; connectedNode.nodeParent = currentNode; _todoList.Add(connectedNode); } } } if (done == false) { return(new List <Node>()); } var path = BuildPath(_doneList); Console.WriteLine("\r\nPath:"); foreach (var n in path) { Console.WriteLine($"{n.id}"); } Console.WriteLine(""); return(path); }
void StepBytepDijkstraBFS() { if (_startNode != null && _endNode != null) { if (_isStep == false) { _isStep = true; _todoList.Clear(); _doneList.Clear(); _todoListDebug.Clear(); _doneListDebug.Clear(); ClearNodesParents(); _done = false; _todoList.Add(_startNode); _todoListDebug.Add(_startNode); } if (_todoList.Count > 0 && _done == false) { var currentNode = _todoList.First(); _todoList.Remove(currentNode); _doneList.Add(currentNode); _todoListDebug.Add(currentNode); _doneListDebug.Add(currentNode); if (currentNode == _endNode) { _done = true; } else { for (int i = 0; i < currentNode.connections.Count; i++) { var connectedNode = currentNode.connections[i]; if (connectedNode.enabled && !(_todoList.Contains(connectedNode) || _doneList.Contains(connectedNode))) { float distanceFromStart = PointTools.PointDistance(currentNode.location, _startNode.location); float distanceToNew = PointTools.PointDistance(connectedNode.location, currentNode.location); connectedNode.distanceCost = distanceFromStart + distanceToNew; } else { connectedNode.distanceCost = -1; } } var sortedConnections = currentNode.connections.Where(n => n.distanceCost > 0).OrderBy(n => n.distanceCost); foreach (var sortedConnection in sortedConnections) { var connectedNode = sortedConnection; connectedNode.nodeParent = currentNode; _todoList.Add(connectedNode); } } } if (_done) { _isStep = false; Generate(_startNode, _endNode); } else { DrawFullPath(); } } else { _isStep = false; } }