private void DrawOutsideWalls(PolarGrid polarGrid) { Vector2Int center = Center; int rowLength = polarGrid.RowLength(polarGrid.RowCount - 1) * 2; float theta = Mathf.PI * 2.0f / (float)rowLength; float inRadius = cellHeight * polarGrid.RowCount; Vector2 cwDir = Vector2.right; Vector2 ccwDir = Vector2.right; float accumAngle = 0.0f; for (int j = 0; j != rowLength; ++j) { cwDir = ccwDir; accumAngle += theta; ccwDir = new Vector2(Mathf.Cos(accumAngle), Mathf.Sin(accumAngle)); // ccw Vector2 ccwInRadius = ccwDir * inRadius; Vector2Int a = center + new Vector2Int((int)ccwInRadius.x, (int)ccwInRadius.y); Vector2 cwInRadius = cwDir * inRadius; Vector2Int c = center + new Vector2Int((int)cwInRadius.x, (int)cwInRadius.y); tex.Line(a, c, wallColor); } }
public override void OnInspectorGUI() { PolarGrid polarGrid = (PolarGrid)target; int newRowCount = EditorGUILayout.IntField("row count", polarGrid.RowCount); EditorGUILayout.LabelField("cell count", polarGrid.Graph.Size.ToString()); if (newRowCount != prevRowCount && newRowCount > 0) { prevRowCount = newRowCount; ChangeSize(newRowCount); } if (prevRowCount > 0) { int builderIndex = EditorGUILayout.Popup(prevBuilderIndex, builderNames); if (builderIndex != prevBuilderIndex || GUILayout.Button("rebuild")) { prevBuilderIndex = builderIndex; RebuildMaze(builders[builderIndex]); } DisplayImage(); } }
void OnEnable() { _grid = target as PolarGrid; _docsURL = "file://" + Application.dataPath + "/Plugins/GridFramework/Documentation/html/" + "class_grid_framework_1_1_grids_1_1_polar_grid.html"; }
private void ChangeSize(int newRowCount) { PolarGrid polarGrid = (PolarGrid)target; polarGrid.RowCount = newRowCount; EditorUtility.SetDirty(target); image.Draw(polarGrid); }
private static void PolarMaze() { var grid = new PolarGrid(10); RecursiveBacktracker.Maze(grid, 0); var img = grid.ToImg(); img.Save("polarGrid.png"); Process.Start("polarGrid.png"); }
//private double obstacleFieldError(GridCarModelState state) //{ // double err = 0; // List<ObstacleState> obstacles = obstacleProvider.GetObstacleStates(1); // foreach (ObstacleState obst in obstacles) // { // double d = ComMath.Normal(state.TargetDist, GridCarModelState.MIN_DIST, GridCarModelState.MAX_DIST, MIN_NEURON_VALUE, MAX_NEURON_VALUE); // double x = Math.Cos(state.TargetAngle - state.TargetFinishAngle) * d; // double y = Math.Sin(state.TargetAngle - state.TargetFinishAngle) * d; // double x0 = ComMath.Normal(obst.pp.position.X, CarModelState.MIN_POS_X, CarModelState.MAX_POS_X, MIN_NEURON_VALUE, MAX_NEURON_VALUE); // double y0 = ComMath.Normal(obst.pp.position.Y, CarModelState.MIN_POS_X, CarModelState.MAX_POS_X, MIN_NEURON_VALUE, MAX_NEURON_VALUE); // double dist = Math.Sqrt((x - x0) * (x - x0) + (y - y0) * (y - y0)); // err += Math.Pow(1 / dist - 1 / obst.radius, 2); // } // return err; //} private static PolarGrid obstaclePolarGrid(IObstaclePositionProvider ops, GridCarModelState state) { List <ObstacleState> obstacles = ops.GetObstacleStates(0); PolarGrid pg = new PolarGrid(); foreach (ObstacleState obst in obstacles) { GridObstacleState gos = GridObstacleState.FromObstacleState(obst, state); pg.AddObstacle(gos); } return(pg); }
private void InitializeRadarChart() { this.radChartView3.AreaType = ChartAreaType.Polar; this.radChartView3.Axes.Add(new PolarAxis()); PolarArea area = this.radChartView3.Area as PolarArea; PolarAxis polarAxis = area.Axes.Get <PolarAxis>()[0]; polarAxis.Minimum = 0d; polarAxis.Maximum = 5d; polarAxis.TickLength = 5; area.ShowGrid = true; PolarGrid grid = (PolarGrid)area.Grid; grid.DrawPolarFills = false; grid.DrawRadialFills = false; grid.BackColor = Color.LightGray; grid.BackColor2 = Color.LightGray; int valuesPerSeries = 8; List <RadarSeries> radarSeries = new List <RadarSeries>(); RadarLineSeries radarLineSeries1 = new RadarLineSeries(); radarLineSeries1.PolarAxis = polarAxis; RadarLineSeries radarLineSeries2 = new RadarLineSeries(); radarLineSeries2.PolarAxis = polarAxis; RadarAreaSeries radarAreaSeries1 = new RadarAreaSeries(); radarAreaSeries1.PolarAxis = polarAxis; radarSeries.Add(radarLineSeries1); radarSeries.Add(radarLineSeries2); radarSeries.Add(radarAreaSeries1); for (int i = 0; i < radarSeriesValues.Length; i++) { int seriesNumber = i / valuesPerSeries; radarSeries[seriesNumber].DataPoints.Add(new CategoricalDataPoint(radarSeriesValues[i])); } radarLineSeries1.PointSize = new SizeF(1f, 1f); radarLineSeries2.PointSize = new SizeF(1f, 1f); radarAreaSeries1.PointSize = new SizeF(1f, 1f); this.radChartView3.Series.Add(radarAreaSeries1); this.radChartView3.Series.Add(radarLineSeries2); this.radChartView3.Series.Add(radarLineSeries1); this.radChartView3.View.Margin = new Padding(20); }
private void DrawWalls(PolarGrid polarGrid) { Vector2Int center = Center; for (int i = 1; i < polarGrid.RowCount; ++i) { int rowLength = polarGrid.RowLength(i); float theta = Mathf.PI * 2.0f / (float)rowLength; float inRadius = cellHeight * (float)i; float outRadius = inRadius + cellHeight; Vector2 cwDir = Vector2.right; Vector2 ccwDir = Vector2.right; float accumAngle = 0.0f; for (int j = 0; j != rowLength; ++j) { cwDir = ccwDir; accumAngle += theta; ccwDir = new Vector2(Mathf.Cos(accumAngle), Mathf.Sin(accumAngle)); // ccw Vector2 ccwInRadius = ccwDir * inRadius; Vector2Int a = center + new Vector2Int((int)ccwInRadius.x, (int)ccwInRadius.y); Vector2 ccwOutRadius = ccwDir * outRadius; Vector2Int b = center + new Vector2Int((int)ccwOutRadius.x, (int)ccwOutRadius.y); Vector2 cwInRadius = cwDir * inRadius; Vector2Int c = center + new Vector2Int((int)cwInRadius.x, (int)cwInRadius.y); // Vector2 cwOutRadius = cwDir * outRadius; // Vector2Int d = center + new Vector2Int((int)cwOutRadius.x, (int)cwOutRadius.y); int vertex = polarGrid.RowColIndex(i, j); int inward = polarGrid.Inward(new Position(i, j)); int ccwVertex = polarGrid.CCW(new Position(i, j)); if (!polarGrid.Graph.AreLinked(vertex, inward)) { tex.Line(a, c, wallColor); } if (!polarGrid.Graph.AreLinked(vertex, ccwVertex)) { tex.Line(a, b, wallColor); } } } }
public void Draw(PolarGrid maze, Color[] distances = null) { int size = cellHeight * maze.RowCount * 2; tex.Resize(size, size); if (distances != null) { PaintDistances(maze, distances); } else { tex.Fill(backgroundColor); } DrawOutsideWalls(maze); DrawWalls(maze); tex.Apply(); }
private void PaintDistances(PolarGrid polarGrid, Color[] vertexDistanceColors) { Vector2 center = Center; int maxRadius = cellHeight * polarGrid.RowCount; float TwoPi = Mathf.PI * 2.0f; for (int y = 0; y != tex.height; ++y) { for (int x = 0; x != tex.width; ++x) { Color color; // inside circle? Vector2 fromCenter = new Vector2(x, y) - center; float magnitude = fromCenter.magnitude; if (magnitude < maxRadius) { int row = (int)(magnitude / (float)cellHeight); float theta = TwoPi / polarGrid.RowLength(row); float angle = Vector2.SignedAngle(Vector2.right, fromCenter.normalized) * Mathf.Deg2Rad; if (angle < 0.0f) { angle += TwoPi; } int col = (int)(angle / theta); int vertex = polarGrid.RowColIndex(row, col); color = vertexDistanceColors[vertex]; } else { color = backgroundColor; } tex.SetPixel(x, y, color); } } }
private void DrawMaze(object sender, EventArgs e) { if (cbAlgorithm.SelectedItem != null) { Image img; var grid = new Grid(MazeSize, MazeSize); if (pbMask.Image != null) { var mask = Mask.FromBitmap((Bitmap)pbMask.Image); grid = new MaskedGrid(mask); } else if (_mode == MazeStyle.Polar) { grid = new PolarGrid(MazeSize); } else if (_mode == MazeStyle.Hex) { grid = new HexGrid(MazeSize, MazeSize * 3 / 2); } else if (_mode == MazeStyle.Triangle) { grid = new TriangleGrid(MazeSize, MazeSize * 2); } else if (_mode == MazeStyle.Upsilon) { grid = new UpsilonGrid(MazeSize, MazeSize); } else if (_mode == MazeStyle.Weave) { grid = new WeaveGrid(MazeSize, MazeSize); } if (!CreateSelectedMaze(grid)) { return; } img = grid.ToImg(GridSize, (float)nudInset.Value); pbMaze.Image = img; } }
private void RebuildMaze(VertexLinker builder) { Debug.Log("rebuilding " + builder.ToString()); PolarGrid maze = (PolarGrid)target; maze.Graph.ClearLinks(); builder.Build(new VertexLinkerHelper(maze.Graph, maze.AdjacentGraph)); EditorUtility.SetDirty(maze); BreadthFirst bf = new BreadthFirst(maze.Graph, 0); bf.Run(); int[] distances = bf.Distances; float maxDistance = (float)bf.MaxDistance; Color nearColor = Color.red; Color farColor = Color.black; Color[] distanceColors = System.Array.ConvertAll <int, Color>( distances, distance => Color.Lerp(nearColor, farColor, (distance / maxDistance)) ); image.Draw(maze, distanceColors); }
void Awake() { _grid = GetComponent <PolarGrid>(); _col = GetComponent <Collider>(); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Series_PolarGrid)); this.label1 = new System.Windows.Forms.Label(); this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); this.label2 = new System.Windows.Forms.Label(); this.numericUpDown2 = new System.Windows.Forms.NumericUpDown(); this.checkBox1 = new System.Windows.Forms.CheckBox(); this.checkBox2 = new System.Windows.Forms.CheckBox(); this.button1 = new System.Windows.Forms.Button(); this.polarGrid1 = new Steema.TeeChart.Styles.PolarGrid(); this.panel1.SuspendLayout(); this.chartContainer.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit(); this.SuspendLayout(); // // textBox1 // this.textBox1.Text = "Displays an array of values as a circular grid of cells, very similar to a for ex" + "ample hard disk plate with sectors and tracks. Use the AddCell method to populat" + "e series with data."; // // panel1 // this.panel1.Controls.Add(this.button1); this.panel1.Controls.Add(this.checkBox2); this.panel1.Controls.Add(this.checkBox1); this.panel1.Controls.Add(this.numericUpDown2); this.panel1.Controls.Add(this.label2); this.panel1.Controls.Add(this.numericUpDown1); this.panel1.Controls.Add(this.label1); this.panel1.Size = new System.Drawing.Size(440, 64); // // tChart1 // // // // this.tChart1.Aspect.Elevation = 315; this.tChart1.Aspect.ElevationFloat = 315; this.tChart1.Aspect.Orthogonal = false; this.tChart1.Aspect.Perspective = 0; this.tChart1.Aspect.Rotation = 360; this.tChart1.Aspect.RotationFloat = 360; this.tChart1.Aspect.View3D = false; // // // // // // this.tChart1.Axes.Bottom.Increment = 36; // // // // // // // // // this.tChart1.Legend.Title.Pen.Visible = false; this.tChart1.Legend.Visible = false; // // // // // // this.tChart1.Panel.Brush.Color = System.Drawing.Color.FromArgb(((int)(((byte)(115)))), ((int)(((byte)(115)))), ((int)(((byte)(185))))); // // // this.tChart1.Panel.Brush.Gradient.EndColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255))))); this.tChart1.Panel.Brush.Gradient.MiddleColor = System.Drawing.Color.FromArgb(((int)(((byte)(234)))), ((int)(((byte)(234)))), ((int)(((byte)(234))))); this.tChart1.Panel.Brush.Gradient.StartColor = System.Drawing.Color.FromArgb(((int)(((byte)(234)))), ((int)(((byte)(234)))), ((int)(((byte)(234))))); this.tChart1.Panel.Brush.Gradient.UseMiddle = true; this.tChart1.Series.Add(this.polarGrid1); this.tChart1.Size = new System.Drawing.Size(440, 180); // // chartContainer // this.chartContainer.Location = new System.Drawing.Point(0, 137); this.chartContainer.Size = new System.Drawing.Size(440, 180); // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(12, 13); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(43, 13); this.label1.TabIndex = 0; this.label1.Text = "Sectors"; // // numericUpDown1 // this.numericUpDown1.Location = new System.Drawing.Point(61, 11); this.numericUpDown1.Name = "numericUpDown1"; this.numericUpDown1.Size = new System.Drawing.Size(64, 20); this.numericUpDown1.TabIndex = 1; this.numericUpDown1.Value = new decimal(new int[] { 10, 0, 0, 0 }); this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged); // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(12, 40); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(40, 13); this.label2.TabIndex = 2; this.label2.Text = "Tracks"; // // numericUpDown2 // this.numericUpDown2.Location = new System.Drawing.Point(61, 38); this.numericUpDown2.Name = "numericUpDown2"; this.numericUpDown2.Size = new System.Drawing.Size(64, 20); this.numericUpDown2.TabIndex = 3; this.numericUpDown2.Value = new decimal(new int[] { 10, 0, 0, 0 }); this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged); // // checkBox1 // this.checkBox1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.checkBox1.Location = new System.Drawing.Point(177, 12); this.checkBox1.Name = "checkBox1"; this.checkBox1.Size = new System.Drawing.Size(71, 17); this.checkBox1.TabIndex = 4; this.checkBox1.Text = "Clockwise"; #if VS2005 this.checkBox1.AutoSize = true; this.checkBox1.UseVisualStyleBackColor = true; #endif this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged); // // checkBox2 // this.checkBox2.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.checkBox2.Location = new System.Drawing.Point(254, 12); this.checkBox2.Name = "checkBox2"; this.checkBox2.Size = new System.Drawing.Size(75, 17); this.checkBox2.TabIndex = 5; this.checkBox2.Text = "Axis on top"; #if VS2005 this.checkBox2.AutoSize = true; this.checkBox2.UseVisualStyleBackColor = true; #endif this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged); // // button1 // this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.button1.Location = new System.Drawing.Point(344, 9); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 6; this.button1.Text = "Edit"; #if VS2005 this.button1.UseVisualStyleBackColor = true; #endif this.button1.Click += new System.EventHandler(this.button1_Click); // // polarGrid1 // // // // this.polarGrid1.Brush.Color = System.Drawing.Color.FromArgb(((int)(((byte)(68)))), ((int)(((byte)(102)))), ((int)(((byte)(163))))); this.polarGrid1.ColorEach = false; // // // // // // this.polarGrid1.Marks.Callout.ArrowHead = Steema.TeeChart.Styles.ArrowHeadStyles.None; this.polarGrid1.Marks.Callout.ArrowHeadSize = 8; // // // this.polarGrid1.Marks.Callout.Brush.Color = System.Drawing.Color.Black; this.polarGrid1.Marks.Callout.Distance = 0; this.polarGrid1.Marks.Callout.Draw3D = false; this.polarGrid1.Marks.Callout.Length = 10; this.polarGrid1.Marks.Callout.Style = Steema.TeeChart.Styles.PointerStyles.Rectangle; // // // this.polarGrid1.Pen.Color = System.Drawing.Color.FromArgb(((int)(((byte)(68)))), ((int)(((byte)(102)))), ((int)(((byte)(163))))); // // // // // // // // // this.polarGrid1.Pointer.Brush.Gradient.StartColor = System.Drawing.Color.FromArgb(((int)(((byte)(68)))), ((int)(((byte)(102)))), ((int)(((byte)(163))))); this.polarGrid1.Pointer.Style = Steema.TeeChart.Styles.PointerStyles.Rectangle; this.polarGrid1.RotationAngle = 90; this.polarGrid1.Title = "polarGrid1"; // // // this.polarGrid1.XValues.DataMember = "Sectors"; // // // this.polarGrid1.YValues.DataMember = "Tracks"; // // Series_PolarGrid // this.ClientSize = new System.Drawing.Size(440, 317); this.Name = "Series_PolarGrid"; this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); this.chartContainer.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); }
public void BackGroundChanges() { try { if (chartVu != null) { ArrayList arrObjects = chartVu.GetChartObjectsArrayList(); int iCount = arrObjects.Count; int iDel = 0; if (arrObjects != null) { for (int iCtr = 0; iCtr < iCount; iCtr++) { GraphObj objObject = (GraphObj)arrObjects[iDel]; Type obj = objObject.GetType(); if (obj.Name == "PolarLinePlot" || obj.Name == "PolarScatterPlot") { iDel++; } else { chartVu.DeleteChartObject(objObject); } } } plotbackground = new Background(pPolarTransform, ChartObj.PLOT_BACKGROUND, ChartBG1, ChartBG2, ChartBGDir); chartVu.AddChartObject(plotbackground); background = new Background(pPolarTransform, ChartObj.GRAPH_BACKGROUND, GraphBG1, GraphBG2, GraphBGDir); chartVu.AddChartObject(background); pPolarAxis = pPolarTransform.GetCompatibleAxes(); pPolarAxis.SetColor(_AxisColor); chartVu.AddChartObject(pPolarAxis); pPolarGrid = new PolarGrid(pPolarAxis, PolarGrid.GRID_MAJOR); pPolarGrid.SetColor(_AxisColor); pPolarGrid.LineColor = _AxisColor; chartVu.AddChartObject(pPolarGrid); pPolarAxisLabels = (PolarAxesLabels)pPolarAxis.GetCompatibleAxesLabels(); pPolarAxisLabels.SetColor(_AxisColor); chartVu.AddChartObject(pPolarAxisLabels); if (_ChartFooter != null) { ChartTitle footer = new ChartTitle(pPolarTransform, theFont, _ChartFooter); footer.SetColor(_AxisColor); footer.SetTitleType(ChartObj.CHART_FOOTER); footer.SetTitlePosition(ChartObj.CENTER_GRAPH); footer.SetTitleOffset(8); chartVu.AddChartObject(footer); } chartVu.Update(); } } catch (Exception ex) { } }
public void DrawPolarPlot(double[] mag1, double[] ang1) { try { RemovePreviousObjects(); chartVu = this; Font theLabelFont = new Font("Courier", 10, FontStyle.Regular); string[] sarrxlab = new string[mag1.Length]; int nump1 = mag1.Length; for (int i = 0; i < nump1; i++) { sarrxlab[i] = "Mag " + mag1[i].ToString() + ", Angle " + ang1[i].ToString(); ang1[i] = ChartSupport.ToRadians((double)ang1[i]); } theFont = new Font("Microsoft Sans Serif", 10, FontStyle.Bold); chartVu = this; SimpleDataset Dataset1 = new SimpleDataset("First", mag1, ang1); pPolarTransform = new PolarCoordinates(); pPolarTransform.SetGraphBorderDiagonal(0.25, .2, .75, 0.8); background = new Background(pPolarTransform, ChartObj.GRAPH_BACKGROUND, GraphBG1, GraphBG2, GraphBGDir); chartVu.AddChartObject(background); plotbackground = new Background(pPolarTransform, ChartObj.PLOT_BACKGROUND, ChartBG1, ChartBG2, ChartBGDir); chartVu.AddChartObject(plotbackground); pPolarTransform.AutoScale(Dataset1); pPolarAxis = pPolarTransform.GetCompatibleAxes(); pPolarAxis.SetColor(_AxisColor); chartVu.AddChartObject(pPolarAxis); pPolarGrid = new PolarGrid(pPolarAxis, PolarGrid.GRID_MAJOR); pPolarGrid.SetColor(_AxisColor); chartVu.AddChartObject(pPolarGrid); pPolarAxisLabels = (PolarAxesLabels)pPolarAxis.GetCompatibleAxesLabels(); pPolarAxisLabels.SetColor(_AxisColor); chartVu.AddChartObject(pPolarAxisLabels); ChartAttribute attrib1 = new ChartAttribute(Color.Blue, 2, 0); ChartAttribute attrib2 = new ChartAttribute(Color.Red, .5, 0, Color.Red); attrib2.SetFillFlag(true); thePlot2 = new PolarScatterPlot(pPolarTransform, Dataset1, ChartObj.CIRCLE, attrib2); chartVu.AddChartObject(thePlot2); PolarLinePlot thePlot1 = new PolarLinePlot(pPolarTransform, Dataset1, attrib1); chartVu.AddChartObject(thePlot1); findObj = new CustomFindObj1(chartVu, sarrxlab); findObj.SetDataToolTipFormat(ChartObj.DATA_TOOLTIP_CUSTOM); findObj.SetEnable(true); chartVu.SetCurrentMouseListener(findObj); if (_ChartFooter != null) { ChartTitle footer = new ChartTitle(pPolarTransform, theFont, _ChartFooter); footer.SetColor(Color.Black); footer.SetTitleType(ChartObj.CHART_FOOTER); footer.SetTitlePosition(ChartObj.CENTER_GRAPH); footer.SetTitleOffset(8); chartVu.AddChartObject(footer); } this.SetResizeMode(ChartObj.NO_RESIZE_OBJECTS); } catch (Exception ex) { } }