private Point GetPointDTO(int value, int MaxValue) { Point point = new Point(); DeductionPointDTO beginPT = new DeductionPointDTO(); DeductionPointDTO endPT = new DeductionPointDTO(); int beginInt = 0; int CurrentPosition = 0; double currentDistance = TotalLen / MaxValue * value; endPT = listP.Find((DeductionPointDTO tempPt) => tempPt.LenStart <= currentDistance && tempPt.LenEnd >= currentDistance); if (endPT == null) { endPT = listP[listP.Count - 1]; } beginInt = listP.FindIndex((DeductionPointDTO tempPt) => tempPt.LenStart <= currentDistance && tempPt.LenEnd >= currentDistance) - 1; if (beginInt <= 0) { beginPT = listP[0]; } else { beginPT = listP[beginInt]; } CurrentPosition = (int)((currentDistance - endPT.LenStart) / (endPT.LenEnd - endPT.LenStart) * 100); point = GetCurrentPoint(beginPT.point, endPT.point, CurrentPosition); return(point); }
private void Form1_MouseUp(object sender, MouseEventArgs e) { #region 测试两个点坐标系变换 //if (beginP == new Point()) //{ // beginP = e.Location; // txtBegin.Text = "X:" + beginP.X + ",Y:" + beginP.Y; // Rectangle rectBegin = new Rectangle(beginP, new Size(8, 8)); // rectBegin.Offset(-4, -4); // g.FillEllipse(new SolidBrush(Color.Yellow), rectBegin); //} //else if (endP == new Point()) //{ // endP = e.Location; // txtEnd.Text = "X:" + endP.X + ",Y:" + endP.Y; // Rectangle rectEnd = new Rectangle(endP, new Size(8, 8)); // rectEnd.Offset(-4, -4); // g.FillEllipse(new SolidBrush(Color.Green), rectEnd); // g.DrawLine(new Pen(Color.Red), beginP, endP); // txtQuadrant.Text = GetQuadrant(beginP, endP).ToString(); //} #endregion if (listP.Count == 0) { DeductionPointDTO pt = new DeductionPointDTO(); pt.point = e.Location; pt.LenStart = 0; pt.LenEnd = 0; listP.Add(pt); } else { DeductionPointDTO pt = new DeductionPointDTO(); pt.point = e.Location; pt.LenStart = listP[listP.Count - 1].LenEnd; double lenX = Math.Abs(listP[listP.Count - 1].point.X - e.Location.X); double lenY = Math.Abs(listP[listP.Count - 1].point.Y - e.Location.Y); double distance = Math.Sqrt(Math.Pow(lenX, 2) + Math.Pow(lenY, 2)); TotalLen = TotalLen + distance; pt.LenEnd = TotalLen; listP.Add(pt); } for (int i = 0; i < listP.Count; i++) { Rectangle rect = new Rectangle(listP[i].point, new Size(8, 8)); rect.Offset(-4, -4); g.FillEllipse(new SolidBrush(Color.Green), rect); rect = new Rectangle(listP[i - 1 == -1 ? 0 : i - 1].point, new Size(8, 8)); rect.Offset(-4, -4); g.FillEllipse(new SolidBrush(Color.Green), rect); g.DrawLine(new Pen(Color.Red), listP[i - 1 == -1 ? 0 : i - 1].point, listP[i].point); } }