public void LoadTileMap(SpriteLoader loader, Point[,] mapIndices, int depth) { for (int i = 0; i < mapIndices.GetLength(0); ++i) { for (int j = 0; i < mapIndices.GetLength(1); ++j) { Point tileCoord = mapIndices[i, j]; loader.AddSprite( Texture, new Vector2(i * TileWidth, j * TileHeight), new Rectangle(tileCoord.X * TileWidth, tileCoord.Y * TileHeight, TileWidth, TileHeight), depth); } } }
/// <summary> /// Рисует столбиковую диаграмму /// </summary> /// <param name="pbCanvas">Ccылка на объект PictoreBox для рисования</param> /// <param name="IC">Объект InitialCondition, задающий начальные условия</param> public static void drawDiagramm(ref PictureBox pbCanvas, utils.InitialConditions IC) { Color GlaphColor = Color.FromArgb(Globals.glob_colorRed, Globals.glob_colorGreen, Globals.glob_colorBlue); Point[] arr = new Point[IC.ctx.Xarr.GetLength(0)]; Point[] zeroVertexes = new Point[IC.ctx.Xarr.GetLength(0)]; Point pCenter = new Point(); pCenter.X = (int)((pbCanvas.Width / (Math.Abs(IC.Xmin) + Math.Abs(IC.Xmax))) * Math.Abs(IC.Xmin)); pCenter.Y = (int)((pbCanvas.Height / (Math.Abs(IC.Ymin) + Math.Abs(IC.Ymax))) * Math.Abs(IC.Ymax)); for (int i = 0; i < IC.ctx.Xarr.GetLength(0); i++) { arr[i].X = (int)(pCenter.X + 2 * (IC.ctx.Xarr[i] * IC.scaleX)); zeroVertexes[i].X = arr[i].X; } for (int j = 0; j < IC.ctx.Yarr.GetLength(0); j++) { arr[j].Y = (int)(pCenter.Y - 2 * (IC.ctx.Yarr[j] * IC.scaleY)); zeroVertexes[j].Y = pCenter.Y; } using (Graphics G = pbCanvas.CreateGraphics()) { using (Pen p = new Pen(GlaphColor)) { p.Width = 3; for (int i = 0; i < zeroVertexes.GetLength(0); i++) { G.DrawLine(p, arr[i], zeroVertexes[i]); } } } }
public static Line BestFit(Point[] p) { int n = p.GetLength(0); double m = 0.0; double yi = 0.0; double sigxy = 0.0; double sigx = 0.0; double sigy = 0.0; double sigxx = 0.0; foreach (Point q in p) { if (q.IsEmpty) { n--; continue; } sigxy += q.X*q.Y; sigx += q.X; sigy += q.Y; sigxx += q.X*q.X; } m = (n*sigxy - sigx*sigy)/(n*sigxx-sigx*sigx); yi = (sigy-m*sigx)/n; Line l = new Line(m,yi); return l; }
protected Curve GetLines(Point[,] vertexes) { var curve = new Curve(); var rows = vertexes.GetLength(0); var columns = vertexes.GetLength(1); for (var i = 0; i < rows - 1; i++) { for (var j = 0; j < columns - 1; j++) { if (i == 0) { SetCurve(curve, i, j, i, j + 1); } else { SetCurve(curve, i, j, i, j + 1, vertexes); } if (j == 0) { SetCurve(curve, i, j, i + 1, j); } else { SetCurve(curve, i, j, i + 1, j, vertexes); } } } for (var i = 0; i < rows - 1; i++) { SetCurve(curve, i, columns - 1, i + 1, columns - 1); } for (var j = 0; j < columns - 1; j++) { SetCurve(curve, rows - 1, j, rows - 1, j + 1); } return curve; }
internal void plotX(float[] data, float firstY, float incrementY, Pen p) { Point[] pts = new Point[data.GetLength(0)]; for (int i = 0; i < pts.GetLength(0); ++i) { pts[i].X = Convert.ToInt32(xScale * (data[i] - minX)); pts[i].Y = Convert.ToInt32(yScale * (firstY + incrementY * i - maxY)); } lock (this) { offScreenG.DrawLines(p, pts); } }
public void PointTest1() { Point p = new Point(1, 1); Point f = new Point(2, 2); Assert.AreEqual(1, p.X); Assert.AreEqual(1, p.Y); p.X = 2; p.Y = 2; Assert.AreEqual(2, p.X); Assert.AreEqual(2, p.Y); p = p + f; p.GetLength(); }
public static Tuple <int, int> SquareOfClick(Point click) { int temp; int minDist = int.MaxValue; Point[,] boardG = new Point[8, 8]; int[,] boardIndex = new int[8, 8]; #region defining centers for (int i = 0; i < boardG.GetLength(0); i++) { for (int j = 0; j < boardG.GetLength(1); j++) { boardG[i, j] = new Point(i * boardSquareSize.Width + boardSquareCenter.Width, j * boardSquareSize.Height + boardSquareCenter.Height); } } #endregion #region finding the nearest square center for (int i = 0; i < boardG.GetLength(0); i++) { for (int j = 0; j < boardG.GetLength(1); j++) { boardG[i, j] = new Point(boardG[i, j].X - click.X, boardG[i, j].Y - click.Y); temp = boardG[i, j].X * boardG[i, j].X + boardG[i, j].Y * boardG[i, j].Y; // temp is containing the result for the calculation of the distance of centers to the click. // since theres no way to store the distance with the respective square position i putted it in // the point's X because i dont need the point for calculations anymore. boardG[i, j].X = temp; minDist = Math.Min(minDist, temp); } } #endregion #region finding the index of the nearest center for (int i = 0; i < boardG.GetLength(0); i++) { for (int j = 0; j < boardG.GetLength(0); j++) { if (boardG[i, j].X == minDist) { return(Tuple.Create(i, j)); } } } return(Tuple.Create(-1, -1)); #endregion }
private static IEnumerable <GradientStop> ScaleGradientStops(IEnumerable <GradientStop> gradientStops, Point startPoint, Point endPoint, Size targetSize) { if (startPoint.X == endPoint.X) { return(startPoint.Y < endPoint.Y ? ScaleGradientStops(gradientStops, startPoint.Y / targetSize.Height, endPoint.Y / targetSize.Height) : ScaleGradientStops(gradientStops, 1 - startPoint.Y / targetSize.Height, 1 - endPoint.Y / targetSize.Height)); } if (startPoint.Y == endPoint.Y) { return(startPoint.X < endPoint.X ? ScaleGradientStops(gradientStops, startPoint.X / targetSize.Width, endPoint.X / targetSize.Width) : ScaleGradientStops(gradientStops, 1 - startPoint.X / targetSize.Width, 1 - endPoint.X / targetSize.Width)); } Point direction = endPoint - startPoint; double directionLength = direction.GetLength(); double sin = direction.Y / directionLength; double cos = direction.X / directionLength; // generated gradient image size double generatedImageWidth = cos.Abs() * targetSize.Width + sin.Abs() * targetSize.Height; double generatedImageHeight = sin.Abs() * targetSize.Width + cos.Abs() * targetSize.Height; // transformation from a unit square to the generated gradient image rectangle Matrix matrix = Matrix.TranslationMatrix(-0.5, -0.5) * // translate the unit square center to the origin Matrix.ScalingMatrix(generatedImageWidth, generatedImageHeight) * // scale to the generated gradient image size new Matrix(cos, sin, -sin, cos, 0, 0) * // rotate to the generated gradient image angle Matrix.TranslationMatrix(targetSize.Width / 2, targetSize.Height / 2); // translate to the target rectangle center Point relativeStart = startPoint * matrix.Inverse; Point relativeEnd = endPoint * matrix.Inverse; return(ScaleGradientStops(gradientStops, relativeStart.X, relativeEnd.X)); }
public static PathGeometry DrawPolyBezier(Point[] input) { if (input == null) { throw new ArgumentNullException("input"); } if (input.Length == 0) { throw new InvalidOperationException(); } PathGeometry pg = new PathGeometry(); PathFigure pf = new PathFigure(); pf.StartPoint = input[0]; PolyBezierSegment pbs = new PolyBezierSegment(); for (int i = 1; i < input.GetLength(0); i++) pbs.Points.Add(input[i]); pf.Segments.Add(pbs); pg.Figures.Add(pf); return pg; }
public void GenerateInitialPathStep2(List <Point> List) { List.Add(new Point(delta * (-arraySize / 2) + delta / 2, delta * (-arraySize / 2) + delta / 2, 10)); Tuple <int, int> nextPointCoordinates; Point[,] PointsArray1 = new Point[arraySize, arraySize]; int divsionFactor = 2; for (int i = 0; i < PointsArray.GetLength(0); i++) { for (int j = 0; j < PointsArray.GetLength(1); j++) { Point temp = new Point(0, 0, 0); for (int l = -divsionFactor; l < divsionFactor; l++) { for (int m = -divsionFactor; m < divsionFactor; m++) { if ((j + m) < 0 || (i + l) < 0 || (j + m) >= PointsArray.GetLength(1) || (i + l) >= PointsArray.GetLength(0)) { continue; } if (temp.Z < PointsArray[(i + l), (j + m)].Z) { temp.Z = PointsArray[i + l, j + m].Z; } } } PointsArray1[i, j] = temp; } } PointsArray = PointsArray1; for (int i = 0; i < PointsArray.GetLength(0); i++) { for (int j = 0; j < PointsArray.GetLength(1); j++) { // List.Add(new Point(delta * (k - arraySize / 2)+delta/2, delta * (i - arraySize / 2)+delta/2, PointsArray[k, i].Z)); Point nextPoint; //List.Add(new Point(delta * (k - arraySize / 2) + delta / 2, delta * (i - arraySize / 2) + delta / 2, PointsArray[k, i].Z + EpsilonHeight)); List.Add(new Point(delta * (k - arraySize / 2) + delta / 2, delta * (i - arraySize / 2) + delta / 2, getHeight(k, i))); if (j != (PointsArray.GetLength(1) - 1)) { nextPoint = PointsArray[k + step, i]; nextPointCoordinates = new Tuple <int, int>(k + step, i); } else // (j == (PointsArray.GetLength(1) - 1)) { if (i == (PointsArray.GetLength(0) - 1)) { nextPoint = PointsArray1[k, i]; nextPointCoordinates = new Tuple <int, int>(k, i); } else { nextPoint = PointsArray[k, i + 1]; nextPointCoordinates = new Tuple <int, int>(k, i + 1); } } if (nextPoint.Z >= PointsArray[k, i].Z) { List.Add(new Point(delta * (k - arraySize / 2) + delta / 2, delta * (i - arraySize / 2) + delta / 2, getHeight(nextPointCoordinates.Item1, nextPointCoordinates.Item2))); } if (nextPoint.Z < PointsArray[k, i].Z) { List.Add(new Point(delta * (nextPointCoordinates.Item1 - arraySize / 2) + delta / 2, delta * (nextPointCoordinates.Item2 - arraySize / 2) + delta / 2, getHeight(k, i))); } k += step; } k -= step; step = -step; } List.Add(new Point(-delta * (PointsArray1.GetLength(0) - 1 - arraySize / 2) + delta / 2, delta * (PointsArray1.GetLength(1) - 1 - arraySize / 2) + delta / 2, 10)); }
public List<Point> calcPossibleMoves(Rectangle selectedObject, Canvas gameCanvas, int[] rollResults, Point[,] gridCoordinatesArray, int gridCirclesCount) { for (int i = 0; i < rollResults.Length; i++) { if (rollResults[i] == 5 || rollResults[i] == 6) { playerMovesCount++; } } Point currentPositionCoord = new Point(); currentPositionCoord.X = Canvas.GetLeft(selectedObject) + selectedObject.Width / 2; currentPositionCoord.Y = Canvas.GetTop(selectedObject) + selectedObject.Height / 2; Point currentPositionIndex = new Point(); for (int i = 0; i < gridCoordinatesArray.GetLength(0); i++) { for (int j = 0; j < gridCoordinatesArray.GetLength(1); j++) { if (Math.Abs(currentPositionCoord.X - gridCoordinatesArray[i, j].X) < 1 && Math.Abs(currentPositionCoord.Y - gridCoordinatesArray[i, j].Y) < 1) { currentPositionIndex.X = i; currentPositionIndex.Y = j; if (j == 0) { currentPositionIndex.X = 0; } } } } ((MainWindow)System.Windows.Application.Current.MainWindow).labelIJ.Content = string.Format("I,J: {0},{1}", currentPositionIndex.X, currentPositionIndex.Y); for (int i = 0; i < gridCoordinatesArray.GetLength(0); i++) { for (int j = 0; j < gridCoordinatesArray.GetLength(1); j++) { if ((Math.Abs(j - currentPositionIndex.Y) == 1 && (i - currentPositionIndex.X) == 0) || (((Math.Abs(i - currentPositionIndex.X) == 1) || (Math.Abs(i - currentPositionIndex.X) == 15)) && (j - currentPositionIndex.Y) == 0)) { if (currentPositionIndex.Y % 2 == 0 && currentPositionIndex.X <= i) { movePositionsArray.Add(gridCoordinatesArray[i, j]); } if (currentPositionIndex.Y % 2 != 0 && currentPositionIndex.X >= i) { movePositionsArray.Add(gridCoordinatesArray[i, j]); } if (currentPositionIndex.Y == gridCirclesCount) { movePositionsArray.Add(gridCoordinatesArray[i, j]); } } } if (currentPositionIndex == new Point(0, 0)) { movePositionsArray.Add(gridCoordinatesArray[i, 1]); } } return movePositionsArray; }
internal static void DrawConnectors(Graphics graphics, Pen pen, Point[] points, Size connectorCapSize, Size maxCapSize, LineAnchor startConnectorCap, LineAnchor endConnectorCap) { if (points.GetLength(0) >= 2) { GraphicsPath path = null; float capinset = 0f; if (startConnectorCap != LineAnchor.None) { Point[] pointArray = new Point[] { points[0], points[1] }; int num2 = (pointArray[0].Y == pointArray[1].Y) ? connectorCapSize.Width : connectorCapSize.Height; num2 += num2 % 2; num2 = Math.Min(Math.Min(num2, maxCapSize.Width), maxCapSize.Height); path = GetLineCap(startConnectorCap, num2, out capinset); if (((path != null) && ((startConnectorCap % LineAnchor.ArrowAnchor) == LineAnchor.None)) && ((pointArray[0].X == pointArray[1].X) || (pointArray[0].Y == pointArray[1].Y))) { Matrix transform = graphics.Transform; graphics.TranslateTransform((float) pointArray[0].X, (float) pointArray[0].Y); if (pointArray[0].Y == pointArray[1].Y) { graphics.RotateTransform((pointArray[0].X < pointArray[1].X) ? 90f : 270f); } else { graphics.RotateTransform((pointArray[0].Y < pointArray[1].Y) ? 180f : 0f); } using (Brush brush = new SolidBrush(pen.Color)) { graphics.FillPath(brush, path); graphics.DrawPath(pen, path); } graphics.Transform = (transform != null) ? transform : new Matrix(); } } GraphicsPath path2 = null; float num3 = 0f; if (endConnectorCap != LineAnchor.None) { Point[] pointArray2 = new Point[] { points[points.GetLength(0) - 2], points[points.GetLength(0) - 1] }; int num4 = (pointArray2[0].Y == pointArray2[1].Y) ? connectorCapSize.Width : connectorCapSize.Height; num4 += num4 % 2; num4 = Math.Min(Math.Min(num4, maxCapSize.Width), maxCapSize.Height); path2 = GetLineCap(endConnectorCap, num4, out num3); if (((path2 != null) && ((endConnectorCap % LineAnchor.ArrowAnchor) == LineAnchor.None)) && ((pointArray2[0].X == pointArray2[1].X) || (pointArray2[0].Y == pointArray2[1].Y))) { Matrix matrix2 = graphics.Transform; graphics.TranslateTransform((float) pointArray2[1].X, (float) pointArray2[1].Y); if (pointArray2[0].Y == pointArray2[1].Y) { graphics.RotateTransform((pointArray2[0].X < pointArray2[1].X) ? 270f : 90f); } else { graphics.RotateTransform((pointArray2[0].Y < pointArray2[1].Y) ? 0f : 180f); } using (Brush brush2 = new SolidBrush(pen.Color)) { graphics.FillPath(brush2, path2); graphics.DrawPath(pen, path2); } graphics.Transform = (matrix2 != null) ? matrix2 : new Matrix(); } } if (path != null) { CustomLineCap cap = new CustomLineCap(null, path) { WidthScale = 1f / pen.Width, BaseInset = capinset }; pen.CustomStartCap = cap; } if (path2 != null) { CustomLineCap cap2 = new CustomLineCap(null, path2) { WidthScale = 1f / pen.Width, BaseInset = num3 }; pen.CustomEndCap = cap2; } graphics.DrawLines(pen, points); if (path != null) { CustomLineCap customStartCap = pen.CustomStartCap; pen.StartCap = LineCap.Flat; customStartCap.Dispose(); } if (path2 != null) { CustomLineCap customEndCap = pen.CustomEndCap; pen.EndCap = LineCap.Flat; customEndCap.Dispose(); } } }
public static PathGeometry DrawPolyBezier(Point[] input) { PathGeometry pg = new PathGeometry(); PathFigure pf = new PathFigure(); pf.StartPoint = input[0]; PolyBezierSegment pbs = new PolyBezierSegment(); for (int i = 1; i < input.GetLength(0); i++) pbs.Points.Add(input[i]); pf.Segments.Add(pbs); pg.Figures.Add(pf); return pg; }
public static Point[] CatmullRom(Point[] input) { if (input.GetLength(0) < 3) { throw new InvalidOperationException(); } int inputLength = input.GetLength(0); Point[] ans = new Point[3 * (inputLength - 2) + 4]; ans[0] = input[0]; ans[1] = input[0]; for (int i = 0; i < input.GetLength(0) - 2; i++) { Point p1 = input[i]; Point p2 = input[i + 1]; Point p3 = input[i + 2]; Vector v1 = p2 - p3; Vector v2 = p1 - p3; double theta = Math.Abs(Vector.AngleBetween(v1, v2)); double h = v1.Length * Math.Sin(theta * Math.PI / 180.0); double deltai = Math.Sqrt(Math.Pow(v1.Length, 2) - h * h); Vector v3 = p2 - p1; double deltai_1 = Math.Sqrt(Math.Pow(v3.Length, 2) - h * h); Point b3i_1 = p2 - (deltai_1 / (3 * (deltai + deltai_1))) * (p3 - p1); Point b3i_2 = p2 + (deltai / (3 * (deltai + deltai_1))) * (p3 - p1); ans[2 + 3 * i] = b3i_1; ans[2 + 3 * i + 1] = input[i + 1]; ans[2 + 3 * i + 2] = b3i_2; } ans[ans.GetLength(0) - 2] = input[inputLength - 1]; ans[ans.GetLength(0) - 1] = input[inputLength - 1]; return ans; }
private Boolean CheckPointsArray(Point[] expected, Point[] actual) { Boolean equal = false; int matches = 0; int lenght = expected.GetLength(0); for (int i = 0; i < lenght; i++) { if ((expected[i].X == actual[i].X) && (expected[i].Y == actual[i].Y)) { matches++; } } if (matches == lenght) { equal = true; } return equal; }
protected override void Init() { iPossibleDealerPos = new Point[][] { new Point [] //9 max black { new Point(598, 132), new Point(656, 191), new Point(615, 309), new Point(507, 370), new Point(311, 370), new Point(231, 363), new Point(133, 241), new Point(162, 151), new Point(298, 131), }, new Point [] // 9 max standard { new Point(534, 162), new Point(618, 205), new Point(644, 309), new Point(509, 390), new Point(312, 400), new Point(254, 387), new Point(120, 286), new Point(139, 220), new Point(279, 151), }, }; iPossibleBetPos = new Point[][] { new Point[] //9 max black { new Point(490 - KBetWidth, 122), new Point(595 - KBetWidth, 172), new Point(617 - KBetWidth, 240), new Point(560, 312), new Point(446, 317), new Point(290, 346), new Point(200, 292), new Point(135 - KBetWidth, 198), new Point(160, 122) }, new Point[] //9 max standard { new Point(450 - KBetWidth, 165), new Point(575 - KBetWidth, 203), new Point(645 - KBetWidth, 265), new Point(580, 317), new Point(448, 364), new Point(290, 362), new Point(174, 308), new Point(150, 230), new Point(290, 177) }, }; iPossiblestackPos = new Point[][] { new Point [] //9 max black { new Point(498, 82), new Point(652, 156), new Point(650, 295), new Point(548, 419), new Point(335, 433), new Point(118, 419), new Point(20, 295), new Point(22, 156), new Point(175, 82), }, new Point [] //9 max standard { new Point(495, 117), new Point(675, 190), new Point(710, 346), new Point(565, 453), new Point(365, 479), new Point(175, 453), new Point(20, 346), new Point(65, 190), new Point(240, 117), }, }; iHandCardLocs = new Point[][] { new Point [] //9 max black theme { new Point(510, 0), new Point(663, 60), new Point(663, 199), new Point(559, 323), new Point(347, 337), new Point(129, 323), new Point(31, 199), new Point(31, 60), new Point(181, 0) }, new Point [] //9 max standard theme { new Point(474, 23), new Point(654, 96), new Point(687, 252), new Point(540, 359), new Point(349, 385), new Point(152, 359), new Point(8, 252), new Point(40, 96), new Point(220, 23) }, }; for (int i = iPossibleDealerPos.GetLength(0) - 1; i >= 0; i--) { for (int j = iPossibleDealerPos[i].Length - 1; j >= 0; j--) { //iPossibleDealerPos[i][j].X += 2; iPossibleDealerPos[i][j].Y += 7; } } determineTableType(); if (iTableIndex == -1) { data.error = 9; data.errorStr = "Can't determine table type. All stacks must be visible."; } }
static void Main(string[] args) { //making a 1D array int[] my1DArray = new int[3]; //how to make a 2D array? int[,] my2DArray = new int[3, 3]; //populate our 2D array with random values // (how to go through an array) int counter = 1; for (int y = 0; y < 3; y++) { //for each Y (row) for (int x = 0; x < 3; x++) { //for each X (column) //set the value at that X,Y coordinate to the value of the counter my2DArray[x, y] = counter; //increase the counter counter++; } } //writing out a grid for (int y = 0; y < 3; y++) { //for each Y (row) for (int x = 0; x < 3; x++) { //for each X (column) //write to the grid Console.Write("[{0}] ", my2DArray[y, x]); } //end of row, kick down to next line. Console.WriteLine(); } //create a 2D Array of Points Point[,] pointArray = new Point[10, 10]; for (int y = 0; y < pointArray.GetLength(1); y++) { //for each row for (int x = 0; x < pointArray.GetLength(0); x++) { //for each column pointArray[x, y] = new Point(x, y); } } Point somePoint = pointArray[2, 6]; //using arrows for movement //putting a single keystroke into a variable ConsoleKeyInfo input = Console.ReadKey(); switch (input.Key) { case ConsoleKey.LeftArrow: //do left arrow stuff break; case ConsoleKey.RightArrow: // do right arrow stuff break; case ConsoleKey.UpArrow: //do up arrow shenanigans break; case ConsoleKey.DownArrow: Console.WriteLine("Down arrow for days"); break; default: //invalid Console.WriteLine("Not an arrow"); break; } Console.ReadKey(); }
static void Main(string[] args) { //how to make a 1D array int[] my1DArray = new int[10]; //how to make a 2D array int[,] my2DArray = new int[3, 3]; //populate our 2D array with incremental values //how to go through an array int counter = 1; for (int y = 0; y < 3; y++) { //for each Y (row) for (int x = 0; x < 3; x++) { //for each X (column) my2DArray[x, y] = counter; counter++; } } for (int y = 0; y < 3; y++) { //for each Y (row) for (int x = 0; x < 3; x++) { //for each X (column) Console.Write("[{0}] ", my2DArray[x, y]); } //end of row go down to next line Console.WriteLine(); } //creat a 2D array of Points Point[,] pointArray = new Point[10, 10]; for (int y = 0; y < pointArray.GetLength(1); y++) { //for each Y (row) for (int x = 0; x < pointArray.GetLength(0); x++) { //for each X (column) pointArray[x, y] = new Point(x, y); } } //using arrows for movement //putting a single key stroke into a variable ConsoleKeyInfo input = Console.ReadKey(); switch (input.Key) { case ConsoleKey.LeftArrow: //do left arrow stuff break; case ConsoleKey.RightArrow: //do right arrow stuff break; case ConsoleKey.UpArrow: //do up arrow stuff break; case ConsoleKey.DownArrow: //do down arrow stuff break; default: //invalid break; } Console.ReadKey(); }
/// <summary> /// Отрисовка сетки по форме функции /// </summary> /// <param name="xMin">Минимальная координата функции по оси X</param> /// <param name="yMin">Минимальная координата функции по оси Y</param> /// <param name="xMax">Максимальная координата функции по оси X</param> /// <param name="yMax">Максимальная координата функции по оси Y</param> /// <param name="x0">Положение начала координат относительно контейнера по оси X</param> /// <param name="y0">Положение начала координат относительно контейнера по оси Y</param> /// <param name="structStep">Шаг сетки</param> /// <param name="g">Графический контейнер, в котором будет производиться отрисовка</param> void DrawStructure2(double xMin, double yMin, double xMax, double yMax, int x0, int y0, int structStep, Graphics g) { Point[,] structPoints = new Point[(int)(xMax - xMin) / structStep + 1, (int)(yMax - yMin) / structStep + 1]; //точки, по которым производятся вычисления int pcnt = 0, qcnt = 0; //счетчики for (double p = xMin; p <= xMax; p += structStep) //в цикле проходим по всем точкам на оси Х { qcnt = 0; for (double q = yMin; q <= yMax; q += structStep) //в цикле проходим по всем точкам на оси Y { Point newPoint = GetPoint(p, q); //Вычисляем значение функции в точке (спроецированное на текущую плоскость) // if (!(newPoint.X <= -x0 || newPoint.Y <= -y0 || newPoint.X > pictureBox1.Width || newPoint.Y > pictureBox1.Height)) //Если функция не вернула ошибку, то: { structPoints[pcnt, qcnt] = new Point(x0 + newPoint.X, y0 - newPoint.Y); //добавляем точку в массив для отрисовки } qcnt++; } pcnt++; } List<Point> pointArr = new List<Point>(); //Список точек для отрисовкки for (int i = 0; i < structPoints.GetLength(0) - 1; i++) //проходим по всем точкам в массиве по оси Х { pointArr.Clear(); //Очищаем список точек для отрисовки for (int j = 0; j < structPoints.GetLength(1) - 1; j++)//проходим по всем точкам в массиве по оси Y { if (!(structPoints[i, j].X == 0 && structPoints[i, j].Y == 0))//Если в точке нет ошибки, то { pointArr.Add(structPoints[i, j]); //Добавляем точку в список отрисовки } } if (pointArr.Count > 1) //Если список отрисовки создан, то { g.DrawCurve(new Pen(netColor, 1), pointArr.ToArray()); //Рисуем кривую по точкам из списка отрисовки } } for (int i = 0; i < structPoints.GetLength(1) - 1; i++)//проходим по всем точкам в массиве по оси Y { pointArr.Clear(); //Очищаем список точек для отрисовки for (int j = 0; j < structPoints.GetLength(0) - 1; j++)//проходим по всем точкам в массиве по оси X { if (!(structPoints[j, i].X == 0 && structPoints[j, i].Y == 0))//Если в точке нет ошибки, то { pointArr.Add(structPoints[j, i]);//Добавляем точку в список отрисовки if (pointsCB.Checked) g.DrawString("[" + (structPoints[j, i].X).ToString() + ";" + (structPoints[j, i].Y).ToString() + "]", new Font("Arial", 8f, FontStyle.Regular), new SolidBrush(coordColor), structPoints[j, i]);//Если отмечен соответствующий чекбокс, то рисуем надпись над точкой } } if (pointArr.Count > 1)//Если список отрисовки создан, то { g.DrawCurve(new Pen(netColor, 1), pointArr.ToArray());//Рисуем кривую по точкам из списка отрисовки } } }
//int howmuchisdone = 0; void DrawStructure2(int xMin, int yMin, int xMax, int yMax, int x0, int y0, int structStep, Graphics g) { Point[,] structPoints = new Point[(xMax - xMin) / structStep + 1, (yMax - yMin) / structStep + 1]; int pcnt = 0, qcnt = 0; for (double p = xMin; p <= xMax; p += structStep) { qcnt = 0; for (double q = yMin; q <= yMax; q += structStep) { // howmuchisdone++; Point newPoint = GetPoint(p, q); if (!(newPoint.X < -10000 || newPoint.Y < -10000)) { structPoints[pcnt, qcnt] = new Point(x0 + newPoint.X, y0 - newPoint.Y); } qcnt++; } pcnt++; } List<Point> pointArr = new List<Point>(); for (int i = 0; i < structPoints.GetLength(0) - 1; i++) { pointArr.Clear(); for (int j = 0; j < structPoints.GetLength(1) - 1; j++) { if (!structPoints[i, j].IsEmpty) { pointArr.Add(structPoints[i, j]); } } if (pointArr.Count > 1) { g.DrawCurve(new Pen(netColor, 1), pointArr.ToArray()); } } for (int i = 0; i < structPoints.GetLength(1) - 1; i++) { pointArr.Clear(); for (int j = 0; j < structPoints.GetLength(0) - 1; j++) { if (!structPoints[i, j].IsEmpty) { pointArr.Add(structPoints[j, i]); } } if (pointArr.Count > 1) { g.DrawCurve(new Pen(netColor, 1), pointArr.ToArray()); } } //howmuchisdone = 0; }
/// <summary> /// IsInsidePolygon takes a pollygon as an array of points as type Point and determines /// if a testpoint as type Point is within the polygon /// </summary> /// <param name="polygon">array of type Point that defines a polygon</param> /// <param name="testPoint">a point of type Point to test</param> /// <returns>True if the point is within the polygon, else false</returns> public static bool IsInsidePolygon(Point[] polygon, Point testPoint) { bool ret = true; Point p1; Point p2; Int32 indx; double xcross; Int32 counter = 0; if (polygon.GetLength(0) < 3) ret = false; // polygon isn't even a triangle else foreach (Point corner in polygon) if (corner.X == testPoint.X && corner.Y == testPoint.Y) ret = false; // testPoint is one of the corners if (!ret) return ret; p1 = polygon[polygon.GetLength(0) - 1]; // start with last point hence the closing line segment for (indx = 0; indx < polygon.GetLength(0); indx++) { // This algorithm creates a ray from the test point to the right. It counts the // number of line segments of the polygon that the ray crosses. An even number // means the test point is outside of the polygon, an odd number means the test // point is inside the polygon p2 = polygon[indx]; if (testPoint.Y > System.Math.Min(p1.Y, p2.Y)) if (testPoint.Y <= System.Math.Max(p1.Y, p2.Y)) if (testPoint.X <= System.Math.Max(p1.X, p2.X)) if (p1.Y != p2.Y) // horizontal segments are invalid { xcross = (testPoint.Y - p1.Y) * (p2.X - p1.X) / (p2.Y - p1.Y) + p1.X; if (p1.X == p2.X || testPoint.X <= xcross) counter++; } p1 = p2; } ret = (counter % 2 != 0); return ret; }
internal static void DrawConnector(Graphics graphics, Pen pen, Point[] points, Size connectorCapSize, Size maxCapSize, LineAnchor startConnectorCap, LineAnchor endConnectorCap) { if (points.GetLength(0) < 2) return; points = OptimizeConnectorPoints(points); //First we start with drawing start cap GraphicsPath startCap = null; float startCapInset = 0.0f; if (startConnectorCap != LineAnchor.None) { Point[] startSegment = new Point[] { points[0], points[1] }; int capSize = (startSegment[0].Y == startSegment[1].Y) ? connectorCapSize.Width : connectorCapSize.Height; capSize += (capSize % 2); capSize = Math.Min(Math.Min(capSize, maxCapSize.Width), maxCapSize.Height); startCap = GetLineCap(startConnectorCap, capSize, out startCapInset); //Now if user has requested us to fill the line cap then we do so //THIS IS A WORKAROUND IN FILLING THE CUSTOM CAPS AS GDI+ HAS A bool fill = (startCap != null && (((int)startConnectorCap % 2) == 0) && (startSegment[0].X == startSegment[1].X || startSegment[0].Y == startSegment[1].Y)); if (fill) { Matrix oldTransform = graphics.Transform; graphics.TranslateTransform(startSegment[0].X, startSegment[0].Y); if (startSegment[0].Y == startSegment[1].Y) graphics.RotateTransform((startSegment[0].X < startSegment[1].X) ? 90.0f : 270.0f); else graphics.RotateTransform((startSegment[0].Y < startSegment[1].Y) ? 180.0f : 0.0f); using (Brush penBrush = new SolidBrush(pen.Color)) graphics.FillPath(penBrush, startCap); graphics.Transform = (oldTransform != null) ? oldTransform : new Matrix(); } } GraphicsPath endCap = null; float endCapInset = 0.0f; if (endConnectorCap != LineAnchor.None) { Point[] endSegment = new Point[] { points[points.GetLength(0) - 2], points[points.GetLength(0) - 1] }; int capSize = (endSegment[0].Y == endSegment[1].Y) ? connectorCapSize.Width : connectorCapSize.Height; capSize += (capSize % 2); capSize = Math.Min(Math.Min(capSize, maxCapSize.Width), maxCapSize.Height); endCap = GetLineCap(endConnectorCap, capSize, out endCapInset); //Now if user has requested us to fill the line cap then we do so, //THIS IS A WORKAROUND IN FILLING THE CUSTOM CAPS AS GDI+ HAS A bool fill = (endCap != null && (((int)endConnectorCap % 2) == 0) && (endSegment[0].X == endSegment[1].X || endSegment[0].Y == endSegment[1].Y)); if (fill) { Matrix oldTransform = graphics.Transform; graphics.TranslateTransform(endSegment[1].X, endSegment[1].Y); if (endSegment[0].Y == endSegment[1].Y) graphics.RotateTransform((endSegment[0].X < endSegment[1].X) ? 270.0f : 90.0f); else graphics.RotateTransform((endSegment[0].Y < endSegment[1].Y) ? 0.0f : 180.0f); using (Brush penBrush = new SolidBrush(pen.Color)) graphics.FillPath(penBrush, endCap); graphics.Transform = (oldTransform != null) ? oldTransform : new Matrix(); } } if (startCap != null) { CustomLineCap customStartCap = new CustomLineCap(null, startCap); customStartCap.WidthScale = 1.0f / pen.Width; customStartCap.BaseInset = startCapInset; pen.CustomStartCap = customStartCap; } if (endCap != null) { CustomLineCap customEndCap = new CustomLineCap(null, endCap); customEndCap.WidthScale = 1.0f / pen.Width; customEndCap.BaseInset = endCapInset; pen.CustomEndCap = customEndCap; } using (GraphicsPath path = GetRoundedPath(points, StateDesignerConnector.ConnectorPadding / 2)) { graphics.DrawPath(pen, path); } if (startCap != null) { CustomLineCap disposableLineCap = pen.CustomStartCap; pen.StartCap = LineCap.Flat; disposableLineCap.Dispose(); } if (endCap != null) { CustomLineCap disposableLineCap = pen.CustomEndCap; pen.EndCap = LineCap.Flat; disposableLineCap.Dispose(); } }
/** * Method for painting the canvas. Leave all the paint stuff to me! * */ private void renderSkeleton(int frame, Point[,] animData, Boolean scale) { // Define parameters for painting: int scaling = scale ? 200 : 1; // Scale skeleton points int x = scale ? -(int)RenderWidth / 2 : 0; int y = scale ? -(int)RenderHeight / 2 : 0; int inverse = scale ? -1 : 1; // Do the actual painting: using (DrawingContext dc = this.drawingGroup.Open()) { dc.DrawRectangle(Brushes.Black, null, new Rect(x, y, RenderWidth, RenderHeight)); for (int i = 0; i < animData.GetLength(1); i++) { Point p = new Point(animData[frame, i].X * scaling, animData[frame, i].Y * scaling * inverse); // Check for occlusion if (p.X < x || p.X > RenderWidth || p.Y < y || p.Y > RenderHeight) continue; dc.DrawEllipse(Brushes.Green, null, p, JointThickness, JointThickness); } } }
public void CalculateBezierPoints() { //Fragment do wyznaczania punktów beziera //Wywoływany w konstruktorze klasy i przez metodę Scene.MoveSelectedPoints if (PatchesAreCylinder) { var PatchPoints2 = new Point[VerticalPatches + 3, HorizontalPatches + 3 + 3]; _additionalPoints2 = new Point[VerticalPatches + 3, 1 + 9 + 3 * HorizontalPatches]; _additionalPoints = new Point[1 + 3 * VerticalPatches, 1 + 9 + 3 * HorizontalPatches]; for (int i = 0; i < VerticalPatches + 3; i++) { for (int j = 0; j < HorizontalPatches + 3; j++) { PatchPoints2[i, j] = PatchPoints[i, j]; } } for (int i = 0; i < VerticalPatches + 3; i++) { for (int j = 0; j < 3; j++) { PatchPoints2[i, j + HorizontalPatches + 3] = PatchPoints[i, j]; } } for (int k = 0; k < PatchPoints2.GetLength(0); k++) { var tempCollection = new ObservableCollection <Point>(); for (int i = 0; i < PatchPoints2.GetLength(1); i++) { tempCollection.Add(PatchPoints2[k, i]); } int d = 0; CalculateAdditionalPoints(tempCollection); foreach (var item in _additionalPointsCollection2) { _additionalPoints2[k, d] = item; d++; } } _additionalPointsCollection2.Clear(); for (int k = 0; k < _additionalPoints2.GetLength(1); k++) { var tempCollection = new ObservableCollection <Point>(); for (int i = 0; i < _additionalPoints2.GetLength(0); i++) { tempCollection.Add(_additionalPoints2[i, k]); } int d = 0; CalculateAdditionalPoints(tempCollection); foreach (var item in _additionalPointsCollection2) {//Może warto zmienić kolejność indeksów na d,k teraz k,d? _additionalPoints[d, k] = item; d++; } } } else { for (int k = 0; k < PatchPoints.GetLength(0); k++) { var tempCollection = new ObservableCollection <Point>(); for (int i = 0; i < PatchPoints.GetLength(1); i++) { tempCollection.Add(PatchPoints[k, i]); } int d = 0; CalculateAdditionalPoints(tempCollection); foreach (var item in _additionalPointsCollection2) { _additionalPoints2[k, d] = item; d++; } } _additionalPointsCollection2.Clear(); for (int k = 0; k < _additionalPoints2.GetLength(1); k++) { var tempCollection = new ObservableCollection <Point>(); for (int i = 0; i < _additionalPoints2.GetLength(0); i++) { tempCollection.Add(_additionalPoints2[i, k]); } int d = 0; CalculateAdditionalPoints(tempCollection); foreach (var item in _additionalPointsCollection2) {//Może warto zmienić kolejność indeksów na d,k teraz k,d? _additionalPoints[d, k] = item; d++; } } } CalculateCurvesPatchPoints(); }
public MainViewModel() { // Read file with cityCoordinates. Point[] cityCoordinates = Data.Converter.ArrayToPoint(Data.TextFile.ReadFileToArray<double>(AppDomain.CurrentDomain.BaseDirectory + "berlin52.tsp")); List<Point> cityLayout = new List<Point>(); for (int i = 0; i < cityCoordinates.Length; i++) { cityLayout.Add(cityCoordinates[i]); } TS = new TravelingSalesmanAlgorithm(cityLayout); TS.AlgorithmIsDone_Event += TS_AlgorithmIsDone_Event; DispatcherTimer dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += new EventHandler(UpdateCharts_Tick); dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 50); dispatcherTimer.Start(); // tmp Point[,] tmpArray = new Point[7, 10]; int x = 0; int y = 0; for (int i = 0; i < tmpArray.GetLength(0); i++) { y += 160; x = 0; for (int j = 0; j < tmpArray.GetLength(1); j++) { x += 160; tmpArray[i, j] = new Point(x, y); } } Point[,] fixedArray = new Point[tmpArray.Length, 1]; int index = 0; for (int i = 0; i < tmpArray.GetLength(0); i++) { for (int j = 0; j < tmpArray.GetLength(1); j++) { fixedArray[index, 0] = tmpArray[i, j]; index++; } } Data.TextFile.WritePointArrayToFile("testLayout", fixedArray, true); //**************************************************************** // ObservableProperties //**************************************************************** Cities = new ObservableCollection<Point>(); for (int i = 0; i < cityCoordinates.GetLength(0); i++) { Cities.Add(cityCoordinates[i]); } Route = new ObservableCollection<Point>(); Home = new ObservableCollection<Point>(); Fitness = new ObservableCollection<Point>(); //**************************************************************** // Events //**************************************************************** StartSimulation = new RelayCommand<object>(StartSimulation_Event); ResetSimulation = new RelayCommand<object>(ResetSimulation_Event); StopSimulation = new RelayCommand<object>(StopSimulation_Event); }