// Sets the relativity point, which is essential for most transformations private void SetRelativityPoint(PointF NewPoint) { RealRelatPoint = NewPoint; ScreenRelativityPoint.X = Normalisation.NormaliseX(RealRelatPoint.X, RealBorders[0], RealBorders[1], MainPB.Width); ScreenRelativityPoint.Y = Normalisation.NormaliseY(RealRelatPoint.Y, RealBorders[2], RealBorders[3], MainPB.Height); }
private void SetRelativityPoint(Point NewPoint) { ScreenRelativityPoint = NewPoint; RealRelatPoint.X = (float)Normalisation.DenormaliseX(ScreenRelativityPoint.X, MainPB.Width, RealBorders[0], RealBorders[1]); RealRelatPoint.Y = (float)Normalisation.DenormaliseY(ScreenRelativityPoint.Y, MainPB.Height, RealBorders[2], RealBorders[3]); }
// Draws coordinate axes and markers using PaintEventArgs e private void DrawAxes(PaintEventArgs e) { int yAxisXCoordinate = Normalisation.NormaliseX(0, RealBorders[0], RealBorders[1], MainPB.Width), //Coordinates of axes on the graph xAxisYCoordinate = Normalisation.NormaliseY(0, RealBorders[2], RealBorders[3], MainPB.Height); bool xAxisVisible = true, yAxisVisible = true; if (yAxisXCoordinate < 0) { yAxisXCoordinate = 0; yAxisVisible = false; } else if (yAxisXCoordinate > MainPB.Width) { yAxisXCoordinate = MainPB.Width; yAxisVisible = false; } if (xAxisYCoordinate < 0) { xAxisYCoordinate = 0; xAxisVisible = false; } else if (xAxisYCoordinate > MainPB.Height) { xAxisYCoordinate = MainPB.Height; xAxisVisible = false; } // Get markers values float[] XMarkers = Coordinates.SpreadXMarkers(RealBorders[0], RealBorders[1], (RealBorders[1] - RealBorders[0]) / 10); float[] YMarkers = Coordinates.SpreadYMarkers(RealBorders[2], RealBorders[3], (RealBorders[3] - RealBorders[2]) / 10); // Get markers screen coordinates int[] nXMarkers = Normalisation.NormaliseXArray(XMarkers, RealBorders[0], RealBorders[1], MainPB.Width); int[] nYMarkers = Normalisation.NormaliseYArray(YMarkers, RealBorders[2], RealBorders[3], MainPB.Height); int MarkersRadius = 3; // Draw Font mFont = new Font(Font.FontFamily, 8, FontStyle.Bold); Pen mPen = new Pen(Color.LightGray, 2); SolidBrush mBrush = new SolidBrush(Color.Black); for (int i = 0; i < nXMarkers.Length; i++) { e.Graphics.DrawLine(mPen, nXMarkers[i], 0, nXMarkers[i], MainPB.Height); e.Graphics.FillEllipse(mBrush, nXMarkers[i] - MarkersRadius, xAxisYCoordinate - MarkersRadius, MarkersRadius * 2, MarkersRadius * 2); e.Graphics.DrawString(XMarkers[i].ToString(), mFont, Brushes.Black, nXMarkers[i], xAxisYCoordinate + mFont.Height > MainPB.Height ? xAxisYCoordinate - 1.5f * mFont.Height : xAxisYCoordinate + 2); } for (int i = 0; i < nYMarkers.Length; i++) { e.Graphics.DrawLine(mPen, 0, nYMarkers[i], MainPB.Width, nYMarkers[i]); e.Graphics.FillEllipse(mBrush, yAxisXCoordinate - MarkersRadius, nYMarkers[i] - MarkersRadius, MarkersRadius * 2, MarkersRadius * 2); e.Graphics.DrawString(YMarkers[i].ToString(), mFont, Brushes.Black, yAxisXCoordinate + YMarkers[i].ToString().Length *mFont.Size > MainPB.Width ? yAxisXCoordinate - YMarkers[i].ToString().Length *mFont.Size : yAxisXCoordinate, nYMarkers[i]); } if (yAxisVisible) { e.Graphics.DrawLine(new Pen(Color.Black, 2), yAxisXCoordinate, 0, yAxisXCoordinate, MainPB.Height); } if (xAxisVisible) { e.Graphics.DrawLine(new Pen(Color.Black, 2), 0, xAxisYCoordinate, MainPB.Width, xAxisYCoordinate); } }