private LineProject GetLineProject(MouseEventArgs e) { PointF mousePos = UtilsModel.InvertFromGraph(new PointF(e.X, e.Y), 0, rectLimit.Location.X); PointF graphMouse = UtilsModel.ConvertToGraph(mousePos, rectLimit.Width, rectLimit.Location.X); float length = UtilsModel.LineLength(selectedAxe.Line.P1, selectedAxe.Line.P2); PointF xtm = UtilsModel.CalculateCurrPoint(length, selectedAxe.Angle, rectLimit.Width, rectLimit.Location.X); PointF graphXtm = UtilsModel.ConvertToGraph(xtm, rectLimit.Width, rectLimit.Location.X); float a = graphXtm.X, b = graphXtm.Y, c = -1 * ((graphXtm.X * graphMouse.X) + (graphXtm.Y * graphMouse.Y)); return(new LineProject(a, b, c)); }
private PointF FindPointProject(MouseEventArgs e) { PointF result = new PointF(); if (!this.selectedAxe.Line.IsVertical()) { LineProject projection = this.GetLineProject(e); Line lineForProject = this.GetLineForProject(); float x = (-1 * (lineForProject.B + projection.C)) / (projection.A + projection.B * lineForProject.A); float y = lineForProject.A * x + lineForProject.B; result = UtilsModel.InvertFromGraph(new PointF(x, y), rectLimit.Width, rectLimit.Location.X); } else { PointF mousePos = UtilsModel.InvertFromGraph(new PointF(e.X, e.Y), 0, rectLimit.Location.X); result.X = this.selectedAxe.Line.P1.X; result.Y = mousePos.Y; } return(result); }
private void DragAndDrop_MouseDown(object sender, MouseEventArgs e) { PointF mousePos = UtilsModel.InvertFromGraph(new PointF(e.X, e.Y), 0, rectLimit.Location.X); foreach (Axe axe in axes) { float length = UtilsModel.RuleOfThree(axe.UpperX, UtilsModel.LineLength(axe.Line.P1, axe.Line.P2), axe.CurrValue); PointF tmp = UtilsModel.CalculateCurrPoint(length, axe.Angle, rectLimit.Width, rectLimit.Location.X); float distance = UtilsModel.LineLength(mousePos, tmp); if (distance <= 10) { this.selectedAxe = axe; this.textAxe.Text = this.selectedAxe.Name; this.valeurAxe.Text = this.selectedAxe.CurrValue + ""; this.uniteAxe.Text = this.selectedAxe.Unit; showSimilaire = false; axesSimilsaires = null; break; } } }