/// <summary> /// Sets the transform graphics object in this way that its transformation matrix transforms points (realMiddle, realLeftTop, realRightDown) into ( screenMiddle=(20,300), screenLeftTop=(20,50), screenRightDown=(400,300)). /// </summary> /// <param name="RealMiddle">The "real" coordinates of the middle of the plot.</param> /// <param name="RealLeftTop">The "real" coordinates of the left top point of the plot.</param> /// <param name="RealRightDown">The "real" coordinates of the right down point of the plot.</param> /// <param name="Transform">The graphics object storing transformation matrix from "screen" to "plot" coordinates.</param> static public void SetGraphics(MyPointDouble realMiddle, MyPointDouble realLeftTop, MyPointDouble realRightDown, ref Graphics transform) { RectangleF RealRectangle = new RectangleF((float)realMiddle.x, (float)realMiddle.y, (float)(realRightDown.x - realMiddle.x), (float)(realLeftTop.y - realMiddle.y)); const float MiddleX = 20.0F; const float MiddleY = 300.0F; const float RightX = 400.0F; const float TopY = 50.0F; PointF screenMiddle = new PointF(MiddleX, MiddleY); PointF screenLeftTop = new PointF(MiddleX, TopY); PointF screenRightDown = new PointF(RightX, MiddleY); PointF[] ScreenArray = { screenMiddle, screenLeftTop, screenRightDown }; System.Drawing.Drawing2D.Matrix Transformation = new System.Drawing.Drawing2D.Matrix(RealRectangle, ScreenArray); transform.Transform = Transformation; }
/// <summarly> /// Makes the color plot of the function whose values at the polygon polygons[i-1] is values[i-1] /// </summary> /// <param name="graphl">the object at which the plot will be drawn</param> /// <param name="polygons">the table of polygons</param> /// <param name="values">the table of values</param> /* static public void ColorAreas(ref Graphics graphl, List<MyPolygon> polygons, double[] values, MyGraphOperations.ColorsFunc ColFunc) * { * * if (graphl == null) throw new ArgumentNullException(); * if (polygons.Count() != values.Count()) throw new ArgumentException("The number of elements in polygons is not equal to the number of elements in values"); * for (int Iterator = 1; Iterator <= polygons.Count(); Iterator++) * { * * graphl.FillPolygon(BrushForColor(ColFunc, values[Iterator - 1]), polygons[Iterator - 1].Apexes()); * } * }*/ /// <summary> /// Makes the color plot of the function FunVal in the area Area at the Graphl - the number of divisions along each from both axes is NDiv /// </summary> /// <param name="FunVal"></param> /// <param name="ColFunc"></param> /// <param name="Area"></param> /// <param name="TrMatrix">The matrix which will be used for making transformations of coordinates from the Area to the coordinate system in which the function will be drawn </param> static public void ColorFunc(ref Graphics Graphl, FuncOnPoint FOP, MyGraphOperations.ColorsFunc ColFunc, RectangleF Area, int NDiv, Matrix TrMatrix) { MyPointDouble LeftDownCor = new MyPointDouble(Area.Left, Area.Top, 0.0); MyPointDouble HorizStep = new MyPointDouble(Area.Width / NDiv, 0.0, 0.0); MyPointDouble VertStep = new MyPointDouble(0.0, Area.Height / NDiv, 0.0); MyPointDouble LeftDownCorPlot = LeftDownCor; MyPointDouble HorizStepPlot = HorizStep; MyPointDouble VertStepPlot = VertStep; MyPointDouble PtIter = new MyPointDouble(0.0, 0.0, 0.0); MyPointDouble PtIterPlot = new MyPointDouble(0.0, 0.0, 0.0); MyDrawing.TransformPoint(TrMatrix, ref LeftDownCorPlot); MyDrawing.TransformVector(TrMatrix, ref HorizStepPlot); MyDrawing.TransformVector(TrMatrix, ref VertStepPlot); double heightl = Area.Height / NDiv; double widthl = Area.Width / NDiv; //Matrix AddTransf = new Matrix(1.0F, 0.0F, 0.0F, 1.0F, 0.0F, 50.0F); for (int i = 1; i <= NDiv; i++) { for (int j = 1; j <= NDiv; j++) { PtIter = LeftDownCor + (i - 0.5) * HorizStep + (j - 0.5) * VertStep; PtIterPlot = LeftDownCorPlot + (i - 1.0) * HorizStepPlot + (j - 1) * VertStepPlot; //TransformPoint(AddTransf, ref PtIterPlot); RectangleF RecLoc = new RectangleF((float)(PtIterPlot.x), (float)(PtIterPlot.y), (float)HorizStepPlot.x, (float)VertStepPlot.y); Graphl.FillRectangle(BrushForColor(ColFunc, FOP(PtIter.x, PtIter.y)), RecLoc); } } }
/// <summary> /// Puts into the variable IntersectionPoint the intersection point of line segments (line1Start-line1End) and (line2Start-line2End) /// </summary> /// <param name="line1Start"></param> /// <param name="line1End"></param> /// <param name="line2Start"></param> /// <param name="line2End"></param> /// <param name="IntersectionPoint"></param> /// <returns></returns> public static bool FindIntersection(MyPointDouble line1Start, MyPointDouble line1End, MyPointDouble line2Start, MyPointDouble line2End, ref MyPointDouble IntersectionPoint) { double A11 = -(line1End.Y - line1Start.Y); double A12 = (line1End.X - line1Start.X); double B1 = -line1Start.X * (line1End.Y - line1Start.Y) + line1Start.Y * (line1End.X - line1Start.X); double A21 = -(line2End.Y - line2Start.Y); double A22 = (line2End.X - line2Start.X); double B2 = -line2Start.X * (line2End.Y - line2Start.Y) + line2Start.Y * (line2End.X - line2Start.X); double[,] a = new double[2, 2]; a[1 - 1, 1 - 1] = A11; a[1 - 1, 2 - 1] = A12; a[2 - 1, 1 - 1] = A21; a[2 - 1, 2 - 1] = A22; double[] b = new double[2]; b[1 - 1] = B1; b[2 - 1] = B2; double[] x = new double[2]; bool IsSingular = !alglib.rsolve.rmatrixsolve(a, b, 2, ref x); if ((!IsSingular) && (x[0] >= Math.Min(line1Start.x, line1End.x)) && (x[0] <= Math.Max(line1Start.x, line1End.x))) { IntersectionPoint.SetValues(x[0], x[1], 0.0); return(true); } else { return(false); } }
/// <summary> /// Sets the transform graphics object in this way that its transformation matrix transforms points (realMiddle, realLeftTop, realRightDown) into (screenMiddle, screenLeftTop, screenRightDown). /// </summary> /// <param name="ScreenMiddle">The "screen" coordinates of the middle of the plot. </param> /// <param name="ScreenLeftTop">The "screen" coordinates of the left top point of the plot (we assume that the higher the point lies the larger value has its Y coordinate).</param> /// <param name="ScreenRightDown">The "screen" coordinates of the right down point of the plot. </param> /// <param name="RealMiddle">The "real" coordinates of the middle of the plot.</param> /// <param name="RealLeftTop">The "real" coordinates of the left top point of the plot.</param> /// <param name="RealRightDown">The "real" coordinates of the right down point of the plot.</param> /// <param name="Transform">The graphics object storing transformation matrix from "screen" to "plot" coordinates.</param> static public void SetGraphics(MyPointDouble screenMiddle, MyPointDouble screenLeftTop, MyPointDouble screenRightDown, MyPointDouble realMiddle, MyPointDouble realLeftTop, MyPointDouble realRightDown, ref Graphics transform) { RectangleF RealRectangle = new RectangleF((float)realMiddle.x, (float)realMiddle.y, (float)(realRightDown.x - realMiddle.x), (float)(realLeftTop.y - realMiddle.y)); PointF[] ScreenArray = { screenMiddle.ToPointF(), screenLeftTop.ToPointF(), screenRightDown.ToPointF() }; System.Drawing.Drawing2D.Matrix Transformation = new System.Drawing.Drawing2D.Matrix(RealRectangle, ScreenArray); transform.Transform = Transformation; }