public void Handle(ShapeType message) { selectedShapeType = message; NotifyOfPropertyChange(() => selectedShapeType); _annoShapeModel = null; polylineCollection.Clear(); polygonCollection.Clear(); }
private void OnRightClick(object sender, MouseButtonEventArgs e) { if (_points.Count > 2) { _finalPolygons.Add(_tempPolygon); _tempPolygon = null; _points.Clear(); } }
protected override void OnPreviewMouseRightButtonDown(MouseButtonEventArgs e) { ReleaseMouseCapture(); if (pointsCollection.Count == 0) { NotifyToolFinished(); } if (pointsCollection.Count > 1) { Polyline poly = new Polyline(); Rect b = new Rect(); b.Y = b.X = System.Double.MaxValue; b.Width = b.Height = 0; foreach (Point p in pointsCollection) { if (p.X < b.X) { b.X = p.X; } if (p.Y < b.Y) { b.Y = p.Y; } if (p.X > b.Width) { b.Width = p.X; } if (p.Y > b.Height) { b.Height = p.Y; } } b.Width -= b.X; b.Height -= b.Y; for (int i = 0; i < pointsCollection.Count; i++) { Point pp = new Point(); pp.X = pointsCollection[i].X - b.X; pp.Y = pointsCollection[i].Y - b.Y; pointsCollection[i] = pp;; } poly.Points = pointsCollection.Clone(); pointsCollection.Clear(); Canvas.SetLeft(poly, b.X); Canvas.SetTop(poly, b.Y); poly.Width = b.Width; poly.Height = b.Height; poly.Stroke = Brushes.Black; poly.Fill = Brushes.Transparent; poly.Stretch = Stretch.Fill; NotifyObjectCreated(poly); } pointsCollection.Clear(); objectPrview.RenderOpen().Close(); e.Handled = true; }
private void CalculateData() { Grid.Children.Remove(apoly); Function.Clear(); double step = 1 / Fs; double width = Grid.ColumnDefinitions[0].ActualWidth; double height = Grid.RowDefinitions[0].ActualHeight; double SX = 8 * width * (1 / Fs); double SY = (height * A / 4); Ti = (4 * width) / SX; // PointCollection Function = new PointCollection(); for (double i = 0; i < Ti; i = i + step) { Point cord = new Point(); cord.X = i * SX; cord.Y = 225 - (SY * Math.Sin((2 * Constants.PI * Freq * i) / 180)); Function.Add(cord); } //Polyline apoly = new Polyline(); apoly.Stroke = System.Windows.Media.Brushes.Green; apoly.StrokeThickness = 2; apoly.Points = Function; Grid.Children.Add(apoly); Grid.SetColumnSpan(apoly, 4); Grid.SetRowSpan(apoly, 2); TextFreq.Text = Freq.ToString(); TextAmp.Text = A.ToString(); TextFs.Text = Fs.ToString(); }
private void DrawFigures(Point coords) { Shape figure = null; if (radioEllips.IsChecked == true) { figure = GetEllipse(coords); } if (radioLine.IsChecked == true) { figure = GetLine(coords); } if (radioPlygon.IsChecked == true) { figure = GetPolygon(coords); } if (radioRectangle.IsChecked == true) { figure = GetRectangle(coords); } if (radioSquare.IsChecked == true) { figure = GetSquare(coords); } if (figure != null) { paintField.Children.Add(figure); Points.Clear(); } }
/// <summary> /// function which display Pentagon on canvas and add pentagon to data context /// </summary> public void Execute(object parameter) { var grid = parameter as Grid; _canvas = (Canvas)((Border)((ScrollViewer)grid?.Children[6])?.Content)?.Child; //_shapeCount = _dataContext.Manager.Shapes.Count; _pointCollection.Add(Mouse.GetPosition(_canvas)); ++_count; if (_count == 5) { var listBox = (ListBox)((StackPanel)grid?.Children[5])?.Children[0]; var name = $"Pentagon{++_shapeCount}"; var polygon = new Polygon { Points = _pointCollection.Clone(), Stroke = _dataContext.Settings.StrokeColorBrush, StrokeThickness = _dataContext.Settings.StrokeThickness, Fill = _dataContext.Settings.FillColorBrush }; EnableDrag(polygon); _canvas?.Children.Add(polygon); _pointCollection.Clear(); _count = 0; _dataContext.Manager.Add(polygon, name); listBox?.Items.Refresh(); } }
public void DrawHero(Point position, double angle, List <Point> wayList, bool isHorizontal) { _canvas.Children.Add(_visibleWay); _visWayCollection.Clear(); System.Windows.Point point = new System.Windows.Point(position.X, position.Y); _visWayCollection.Add(point); foreach (var wayPoint in wayList) {/* * if (weakReference.Target == null) * continue; */ point = new System.Windows.Point(wayPoint.X, wayPoint.Y); _visWayCollection.Add(point); } if (isHorizontal) { _canvas.Children.Add(_horizontalAppearance); Canvas.SetLeft(_horizontalAppearance, position.X - _dcenter); Canvas.SetTop(_horizontalAppearance, position.Y - _dcenter); } else { _canvas.Children.Add(_appearance); Canvas.SetLeft(_appearance, position.X - _dcenter); Canvas.SetTop(_appearance, position.Y - _dcenter); _t.Angle = angle; } }
private void canvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e) { if (en == true) { for (int i = 0; i < col.Count; i++) { Line line = new Line(); if (i == col.Count - 1) { line.X1 = col[col.Count - 1].X; line.X2 = col[0].X; line.Y1 = col[col.Count - 1].Y; line.Y2 = col[0].Y; } else { line.X1 = col[i].X; line.X2 = col[i + 1].X; line.Y1 = col[i].Y; line.Y2 = col[i + 1].Y; } line.Stroke = System.Windows.Media.Brushes.Black; line.StrokeThickness = 2; canvas.Children.Add(line); } col.Clear(); } }
public void drawMatrix() { /* * xy1-----xy4 * | | * xy2-----xy3 */ for (int i = 0; i < height; i += 5) { for (int j = 0; j < width; j++) { points[j] = new Point(matrix[i, j] * blockSize, matrix[i + 1, j] * blockSize); } } // clear collection before adding new points _collection.Clear(); foreach (Point p in points) { _collection.Add(p); } // add last point once again to make the square complete //_collection.Add(points[0]); _surface.Points = _collection; }
/// <summary> /// Method used to get polygon points. /// </summary> /// <param name="x1"></param> /// <param name="y1"></param> /// <param name="x2"></param> /// <param name="y2"></param> /// <param name="leftThickness"></param> /// <param name="rightThickness"></param> /// <returns></returns> private PointCollection GetPolygonPoints(double x1, double y1, double x2, double y2, double leftThickness, double rightThickness) { polygonPoints.Clear(); var dx = x2 - x1; var dy = y2 - y1; var radian = Math.Atan2(dy, dx); var cos = Math.Cos(-radian); var sin = Math.Sin(-radian); var x11 = (x1 * cos) - (y1 * sin); var y11 = (x1 * sin) + (y1 * cos); var x12 = (x2 * cos) - (y2 * sin); var y12 = (x2 * sin) + (y2 * cos); cos = Math.Cos(radian); sin = Math.Sin(radian); var leftTopX = (x11 * cos) - ((y11 + leftThickness) * sin); var leftTopY = (x11 * sin) + ((y11 + leftThickness) * cos); var rightTopX = (x12 * cos) - ((y12 + leftThickness) * sin); var rightTopY = (x12 * sin) + ((y12 + leftThickness) * cos); var leftBottomX = (x11 * cos) - ((y11 - rightThickness) * sin); var leftBottomY = (x11 * sin) + ((y11 - rightThickness) * cos); var rightBottomX = (x12 * cos) - ((y12 - rightThickness) * sin); var rightBottomY = (x12 * sin) + ((y12 - rightThickness) * cos); polygonPoints.Add(new Point(leftTopX, leftTopY)); polygonPoints.Add(new Point(rightTopX, rightTopY)); polygonPoints.Add(new Point(rightBottomX, rightBottomY)); polygonPoints.Add(new Point(leftBottomX, leftBottomY)); polygonPoints.Add(new Point(leftTopX, leftTopY)); return(polygonPoints); }
//private Point _start, _end; //List<object> MyBoardObjects; #endregion #region Window Load Events /* * private void MainWindow_Loaded(object sender, RoutedEventArgs e) * { * * }*/ private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { foreach (var obj in MyBoardObjects) { if (obj is Line) { Line line = obj as Line; line.IsEnabled = false; } else if (obj is Rectangle) { Rectangle temprect = obj as Rectangle; temprect.IsEnabled = false; } else if (obj is Ellipse) { Ellipse tempell = obj as Ellipse; tempell.IsEnabled = false; } else if (obj is PointCollection) { PointCollection pntc = obj as PointCollection; pntc.Clear(); } } MyBoardObjects.Clear(); MyBoard.Children.Clear(); }
/// <summary> /// Generates the points and segments of the polygonal Figure object. /// </summary> protected override void BuildFiguresOverride() { _points.Clear(); double initialAngleRad = GeometryHelper.DegreeToRadian(_initialAngle); double angle1Rad = 2 * Math.PI / _sideCount; double angleRad = 0.0; double areaWidth = Double.IsNaN(Width) ? 0.0 : Width / 2; double areaHeight = Double.IsNaN(Height) ? 0.0 : Height / 2; for (int i = 1; i <= _sideCount; i++) { angleRad = (angle1Rad * i) + initialAngleRad; Point p = new Point(); p.X = areaWidth == 0.0 ? Math.Cos(angleRad) : areaWidth + Math.Cos(angleRad) * (areaWidth - StrokeThickness / 2); p.Y = areaHeight == 0.0 ? Math.Sin(angleRad) : areaHeight + Math.Sin(angleRad) * (areaHeight - StrokeThickness / 2); _points.Add(p); } _figure.Segments.Clear(); _figure.StartPoint = _points[0]; for (int i = 0; i < _points.Count; i++) { if (i < _points.Count - 1) { LineSegment segment = new LineSegment(); segment.Point = _points[i + 1]; _figure.Segments.Add(segment); } } Figures.Add(_figure); }
public override void Draw(Canvas canvas) { Point thirdPoint = new Point(); PointCollection pointCollection = new PointCollection(); thirdPoint.X = firstPoint.X - (secondPoint.X - firstPoint.X); thirdPoint.Y = secondPoint.Y; height = (int)Math.Abs(firstPoint.Y - secondPoint.Y); width = (int)Math.Abs(secondPoint.X - thirdPoint.X) / 2; pointCollection.Clear(); pointCollection.Add(firstPoint); pointCollection.Add(secondPoint); pointCollection.Add(thirdPoint); System.Windows.Shapes.Polygon triangle = new System.Windows.Shapes.Polygon() { Points = pointCollection, Stroke = Brushes.Black, StrokeThickness = thickness, Fill = new SolidColorBrush(Colors.Wheat) }; hash = triangle.GetHashCode(); canvas.Children.Add(triangle); }
protected override void Triangulate(DependencyPropertyChangedEventArgs args, Point3DCollection vertices, Vector3DCollection normals, Int32Collection indices, PointCollection textures) { vertices.Clear(); normals.Clear(); indices.Clear(); textures.Clear(); MeshGeometry3D mesh = MeshGenerator.Geometry; foreach (Point3D vertex in mesh.Positions) { vertices.Add(vertex); } foreach (Vector3D normal in mesh.Normals) { normals.Add(normal); } foreach (int index in mesh.TriangleIndices) { indices.Add(index); } foreach (Point texture in mesh.TextureCoordinates) { textures.Add(texture); } }
/// <summary> /// Cleans canvas /// </summary> public void CleanCanvas() { try { MainCanvas.Children.Clear(); points.Clear(); lines.Clear(); polygons.Clear(); dragging = false; selectedPolygon = null; } catch (Exception ex) { throw new ArgumentException(ex.ToString()); } }
/// <summary> /// Toggles the start point of a wipe line. /// </summary> public void ToggleStartPoint() { // Create temporary references to the view model points PolygonPointViewModel tempStart = StartPoint; PolygonPointViewModel tempEnd = EndPoint; // Create temporary references to the model points PolygonPoint startPoint = Line.Points[0]; PolygonPoint endPoint = Line.Points[1]; // Swap the colors on the points tempStart.DeselectedColor = Colors.DodgerBlue; tempEnd.DeselectedColor = Colors.Lime; // Swap the points on the view model PointCollection.Clear(); StartPoint = tempEnd; EndPoint = tempStart; PointCollection.Add(StartPoint); PointCollection.Add(EndPoint); // Swap the points on the model Line.Points.Clear(); Line.Points.Add(endPoint); Line.Points.Add(startPoint); // Fire the collection changed event NotifyPointCollectionChanged(); }
/// <summary> /// Works out the actual X/Y points for the each value within the /// data and draws the line graph. /// </summary> private void UpdateLineGraph() { // Only proceed if there are some actual values and there are enough values if (this.DataValues == null || this.DataValues.Count < 2 || container.ActualHeight == 0 || this.MaxValue <= this.MinValue) { GraphLine.Visibility = Visibility.Hidden; LastPointMarkerEllipse.Visibility = Visibility.Hidden; ScaleCurrentValue.Content = string.Empty; return; } int count = this.DataValues.Count; double max = Math.Max(this.Threshold, this.DataValues.Max()); this.MaxValue = Math.Max(DEFAULT_MAX, max); double scale = this.MaxValue - this.MinValue; double valuePerPoint = container.ActualHeight / scale; double constantOffset = container.ActualWidth / Math.Min(MAX_POINTS, count); double xOffSet = 0; // For each item work out what the actual X/Y should be _graphPoints.Clear(); int start = count > MAX_POINTS ? count - MAX_POINTS : 0; for (int i = start; i < count; i++) { double trueDiff = this.DataValues[i] - this.MinValue; double heightPx = trueDiff * valuePerPoint; double yValue = container.ActualHeight - heightPx; _graphPoints.Add(new Point(xOffSet, yValue)); xOffSet += constantOffset; } // Add Polygon Points GraphLine.Points = _graphPoints; // set LastPointMarkerEllipse Point lastPoint = _graphPoints.Last(); LastPointMarkerEllipse.SetValue(Canvas.LeftProperty, lastPoint.X - (LastPointMarkerEllipse.Width / 2.0)); LastPointMarkerEllipse.SetValue(Canvas.TopProperty, lastPoint.Y - (LastPointMarkerEllipse.Height / 2.0)); LastPointMarkerEllipse.Visibility = Visibility.Visible; // Set label ScaleCurrentValue.Content = this.DataValues.Last().ToString("N0"); ScaleCurrentValue.SetValue(Canvas.LeftProperty, lastPoint.X - (LastPointMarkerEllipse.Width * 2.0)); if (lastPoint.Y < (GraphLine.ActualHeight / 2.0)) { ScaleCurrentValue.SetValue(Canvas.TopProperty, lastPoint.Y + LastPointMarkerEllipse.Height); } else { ScaleCurrentValue.SetValue(Canvas.TopProperty, lastPoint.Y - (LastPointMarkerEllipse.Height * 3.0)); } // Got points now so show graph GraphLine.Visibility = Visibility.Visible; }
private void ResetButton_Click(object sender, RoutedEventArgs e) { // Clear the existing points and graphics. _inputPointCollection.Clear(); _graphicsOverlay.Graphics.Clear(); // Disable the convex hull button. ConvexHullButton.IsEnabled = false; }
private void ResetMeanGraph(object sender, EventArgs e) { if (meanValues.Count > 1) { meanValues.Clear(); meanValues.Add(new Point { X = 0, Y = 0 }); } }
// Methods ------------------------------------------------------------------------------------------ private void UpdateCanvas() { points.Clear(); GeneratePoints(); RenderPoints(); lines.Clear(); GenerateLines(); RenderLines(); }
private void ResetButton_Click(object sender, EventArgs e) { // Clear the existing points and graphics. _inputPointCollection.Clear(); _graphicsOverlay.Graphics.Clear(); // Disable the convex hull button. _convexHullButton.Enabled = false; _convexHullButton.SetTitleColor(UIColor.Gray, UIControlState.Disabled); }
private void SortPointCollection(PointCollection collection) { var points = collection.ToArray(); var sortedPoints = points.OrderBy(point => point.X).ThenBy(point => point.Y).ToArray(); collection.Clear(); foreach (Point point in sortedPoints) { collection.Add(point); } }
/// <summary> /// /// </summary> /// <param name="args"></param> /// <param name="vertices"></param> /// <param name="normals"></param> /// <param name="indices"></param> /// <param name="textures"></param> protected override void Triangulate(DependencyPropertyChangedEventArgs args, Point3DCollection vertices, Vector3DCollection normals, Int32Collection indices, PointCollection textures) { // Clear all four collections. vertices.Clear(); normals.Clear(); indices.Clear(); textures.Clear(); // Fill the vertices, normals, and textures collections. for (int stack = 0; stack <= Stacks; stack++) { double phi = Math.PI / 2 - stack * Math.PI / Stacks; double y = Radius * Math.Sin(phi); double scale = -Radius *Math.Cos(phi); for (int slice = 0; slice <= Slices; slice++) { double theta = slice * 2 * Math.PI / Slices; double x = scale * Math.Sin(theta); double z = scale * Math.Cos(theta); Vector3D normal = new Vector3D(x, y, z); normals.Add(normal); vertices.Add(normal.ToPoint3D()); textures.Add(new Point((double)slice / Slices, (double)stack / Stacks)); } } // Fill the indices collection. for (int stack = 0; stack < Stacks; stack++) { for (int slice = 0; slice < Slices; slice++) { if (stack != 0) { indices.Add((stack + 0) * (Slices + 1) + slice); indices.Add((stack + 1) * (Slices + 1) + slice); indices.Add((stack + 0) * (Slices + 1) + slice + 1); } if (stack != Stacks - 1) { indices.Add((stack + 0) * (Slices + 1) + slice + 1); indices.Add((stack + 1) * (Slices + 1) + slice); indices.Add((stack + 1) * (Slices + 1) + slice + 1); } } } }
private void CalculatePoints() { _points.Clear(); for (var i = 0; i <= 6; i++) { var angleDeg = 60 * i + 30; var angleRad = Math.PI / 180 * angleDeg; _points.Add(new Point(_center.X + _radius * Math.Cos(angleRad), _center.Y + _radius * Math.Sin(angleRad))); } OnPropertyChanged("Points"); }
private void SetSizeTriangle(Polygon shape, double x1, double y1, double x2, double y2) { PointCollection TrianglePoint_resize = new PointCollection(); TrianglePoint_resize.Clear(); TrianglePoint_resize.Add(new Point((x1 < x2 ? x1 : x2), (y1 > y2 ? y1 : y2))); TrianglePoint_resize.Add(new Point((x1 < x2 ? x1 : x2) + (((x1 > x2 ? x1 : x2) - (x1 < x2 ? x1 : x2)) / 2), (y1 < y2 ? y1 : y2))); TrianglePoint_resize.Add(new Point((x1 > x2 ? x1 : x2), (y1 > y2 ? y1 : y2))); shape.Points = TrianglePoint_resize; TrianglePoint = TrianglePoint_resize; }
// find all the corners of a stroke public void FindCorner(Stroke in_stroke, String in_ID) { // initialization m_stroke = in_stroke; m_numP = m_stroke.StylusPoints.Count; Guid tGuid = new Guid(in_ID); m_time = (int[])m_stroke.GetPropertyData(tGuid); m_resamplePoints = new PointCollection(); m_corners = new PointCollection(); m_cornerIndex = new int[500]; int[] old_Index = new int[500]; // pass 0: find all the corners of first resampled point set ResampleStrokes(0); GetCorners(); for (int i = 0; i < m_numC; i++) { old_Index[i] = m_cornerIndex[i]; } int old_numC = m_numC; m_resamplePoints.Clear(); // pass 1: find all the corners of the shifted point set ResampleStrokes(1); GetCorners(); // combine the corners together int cIdx = 1; m_corners.Add(m_resamplePoints[0]); for (int i = 1; i < m_numC; i++) { int idx0 = old_Index[cIdx]; int idx1 = m_cornerIndex[i]; // make sure the two corners are not too close while (idx0 < idx1 - 1) { m_corners.Add(m_resamplePoints[idx0]); cIdx++; idx0 = old_Index[cIdx]; } if (idx0 <= idx1 + 1) { cIdx++; } m_corners.Add(m_resamplePoints[idx1]); } // set number of corners m_numC = m_corners.Count; }
/// <summary> /// Works out the actual X/Y points for the each value within the /// ObservableCollection<GraphDataItem> property. /// </summary> private void ObtainPointsForValues() { //Only proceed if there are some actual values and there are enough values if (DataValues == null || container.ActualHeight == 0 || DataValues.Count < MIN_ITEMS_TO_PLOT) { GraphLine.Visibility = Visibility.Hidden; LastPointMarkerEllipse.Visibility = Visibility.Hidden; ScaleCurrentValue.Content = string.Empty; return; } else { #region Workout Points double scale = MaxValue - MinValue; double valuePerPoint = container.ActualHeight / scale; double constantOffset = container.ActualWidth / DataValues.Count; double xOffSet = 0; ///for each item seen work out what the actual X/Y should be ///based on a bit of Maths _graphPoints.Clear(); for (int i = 0; i < DataValues.Count; i++) { double trueDiff = DataValues[i] - MinValue; double heightPx = trueDiff * valuePerPoint; double yValue = container.ActualHeight - heightPx; _graphPoints.Add(new Point(xOffSet, yValue)); xOffSet += constantOffset; } Point lastPoint = _graphPoints.Last(); //set LastPointMarkerEllipse LastPointMarkerEllipse.SetValue(Canvas.LeftProperty, lastPoint.X - (LastPointMarkerEllipse.Width / 2)); LastPointMarkerEllipse.SetValue(Canvas.TopProperty, lastPoint.Y - (LastPointMarkerEllipse.Height / 2)); LastPointMarkerEllipse.Visibility = Visibility.Visible; #endregion #region Label Current Data Point ScaleCurrentValue.Content = this.DataValues.Last().ToString("N0"); ScaleCurrentValue.SetValue(Canvas.LeftProperty, lastPoint.X - (LastPointMarkerEllipse.Width * 2)); ScaleCurrentValue.SetValue(Canvas.TopProperty, lastPoint.Y - (LastPointMarkerEllipse.Height * 2)); #endregion //Add Polygon Points GraphLine.Points = _graphPoints; //Got points now so show graph GraphLine.Visibility = Visibility.Visible; } }
private void mainWindowUpdate(object sender, EventArgs e) { //WPF requires dispatcher to be invoked to allow for code to be ran from a different thread Application.Current.Dispatcher.Invoke(() => { //Runs update to update the current values g.update(); //Updates the text values, could likely move these into a seperate function for code cleanliness CPUUtil.Text = $"{g.getCPUUtil()}%"; GPUTemp.Text = $"{g.getGPUTemp()}ºC"; RAM.Text = $"{g.getRAM()}MB"; //Open HW Monitor cannot support Ryzen 3000 series at time of writing if (g.getCPUTemp() == 0) { CPUTemp.Text = "Cannot Detect"; } CPUTemp.Text = $"{g.getCPUTemp()}ºC"; GPULoad.Text = $"{g.getGPULoad()}%"; //For drawing the graph, could likely move into it's own function as well which would return a Polyline object double xMax = Graph.Width; double yMax = Graph.Height; double currentY = 0; //The canvas uses the top left as (0,0) currentY = g.graphCalc(Convert.ToInt32(yMax), graphView); points.Add(new Point(x, currentY)); //Increments the x value along the graph, smaller the x value, the tighter the points on the graph and thus the more points shown before the graph resets x += 8; Polyline polyline = new Polyline(); polyline.StrokeThickness = 1; polyline.Stroke = Brushes.White; polyline.Points = points; Graph.Children.Add(polyline); //Current implementation results in losing the final value for the cycle if (x >= xMax) { x = 0; points.Clear(); } }); }
/// <summary> /// Generates the points and segments of the arrow Figure object. /// </summary> protected override void BuildFiguresOverride() { double headLength = _formatRatio * _headLengthRatio; double bodyLength = _formatRatio - headLength; double bodyHeight = _headWidthRatio != 0.0 ? 1.0 / _headWidthRatio : 1.0; double bodyTop = 0.5 - bodyHeight / 2; double bodyBottom = 0.5 + bodyHeight / 2; _points.Clear(); _points.Add(new Point(0.0, bodyTop)); _points.Add(new Point(0.0, bodyBottom)); _points.Add(new Point(bodyLength, bodyBottom)); _points.Add(new Point(bodyLength, 1.0)); _points.Add(new Point(_formatRatio, 0.5)); _points.Add(new Point(bodyLength, 0.0)); _points.Add(new Point(bodyLength, bodyTop)); bool scaling = false; ScaleTransform transform = new ScaleTransform(); if (!Double.IsNaN(Width)) { transform.ScaleX = _formatRatio != 0.0 ? (Width - 2 * StrokeThickness) / _formatRatio : 1.0; scaling = true; } if (!Double.IsNaN(Height)) { transform.ScaleY = Height - 2 * StrokeThickness; scaling = true; } _figure.Segments.Clear(); if (scaling) { _points[0] = transform.Transform(_points[0]); } _figure.StartPoint = _points[0]; for (int i = 0; i < _points.Count; i++) { if (i < _points.Count - 1) { if (scaling) { _points[i + 1] = transform.Transform(_points[i + 1]); } LineSegment segment = new LineSegment(); segment.Point = _points[i + 1]; _figure.Segments.Add(segment); } } Figures.Add(_figure); }
/* * // Static method called for any property change. * static void PropertyChanged(DependencyObject obj, * DependencyPropertyChangedEventArgs args) * { * (obj as TorusMesh).PropertyChanged(args); * } */ /// <summary> /// /// </summary> /// <param name="args"></param> /// <param name="vertices"></param> /// <param name="normals"></param> /// <param name="indices"></param> /// <param name="textures"></param> protected override void Triangulate(DependencyPropertyChangedEventArgs args, Point3DCollection vertices, Vector3DCollection normals, Int32Collection indices, PointCollection textures) { // Clear all four collections. vertices.Clear(); normals.Clear(); indices.Clear(); textures.Clear(); // Fill the vertices, normals, and textures collections. for (int stack = 0; stack <= Stacks; stack++) { double phi = stack * 2 * Math.PI / Stacks; double xCenter = Radius * Math.Sin(phi); double yCenter = Radius * Math.Cos(phi); Point3D pointCenter = new Point3D(xCenter, yCenter, 0); for (int slice = 0; slice <= Slices; slice++) { double theta = slice * 2 * Math.PI / Slices + Math.PI; double x = (Radius + TubeRadius * Math.Cos(theta)) * Math.Sin(phi); double y = (Radius + TubeRadius * Math.Cos(theta)) * Math.Cos(phi); double z = -TubeRadius *Math.Sin(theta); Point3D point = new Point3D(x, y, z); vertices.Add(point); normals.Add(point - pointCenter); textures.Add(new Point((double)slice / Slices, (double)stack / Stacks)); } } // Fill the indices collection. for (int stack = 0; stack < Stacks; stack++) { for (int slice = 0; slice < Slices; slice++) { indices.Add((stack + 0) * (Slices + 1) + slice); indices.Add((stack + 1) * (Slices + 1) + slice); indices.Add((stack + 0) * (Slices + 1) + slice + 1); indices.Add((stack + 0) * (Slices + 1) + slice + 1); indices.Add((stack + 1) * (Slices + 1) + slice); indices.Add((stack + 1) * (Slices + 1) + slice + 1); } } }