안녕하세요. c# wpf로 2D, 3D 그리기를 하고 있는데 궁금한 점이 있어 질문을 드리게 되었습니다.
제가 지금 구현하고자 하는 것은 다음과 같습니다.
- Drawing에 필요한 좌표 정보 값을 입력 받아 Polygon을 그리는 것입니다. 이때 Polygon객체 안에 있는 것은 Line이 될수도 있고, Arc형태의 반 호 일 수도 있습니다.
- 그리고자 하는 Canvas의 중심 좌표를 (0, 0) 으로 하고 싶습니다.
- 그려진 데이터를 Zoom in/out할 수 있는 기능이 필요합니다.
- 추후 3D로 표현이 가능해야 합니다.
처음 해보는 부분이라 여러가지 해보고 있는데 보다 더 유용하고 효율적인 방법이나 유용한 정보 있으시면 공유 부탁드리겠습니다!!!
Polygon 구현 부
PointCollection myPointCollection = new PointCollection();
myPointCollection.Add(new Point(-17.5, 25));
myPointCollection.Add(new Point(17.5, 25));
myPointCollection.Add(new Point(-25, 17.5));
myPointCollection.Add(new Point(-25, -17.5));
myPointCollection.Add(new Point(-17.5, -25));
myPointCollection.Add(new Point(17.5, -25));
myPointCollection.Add(new Point(25, -17.5));
myPointCollection.Add(new Point(25, 17.5));
//myPointCollection.Add(new Point(1, 1));
Polygon myPolygon = new Polygon();
myPolygon.Points = myPointCollection;
myPolygon.Fill = Brushes.Blue;
myPolygon.Width = 100;
myPolygon.Height = 100;
myPolygon.Stretch = Stretch.Fill;
myPolygon.Stroke = Brushes.Black;
myPolygon.StrokeThickness = 2;
PadCanvas.Children.Add(myPolygon);
xaml에서 반호 구현 부
<Canvas Grid.Column="0" x:Name="MyConvas" >
<Path Stroke="Aqua" StrokeThickness="0.1" Fill="Aqua" Stretch="Fill" Width="20" Height="20">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigureCollection>
<PathFigure StartPoint="17.5, -25">
<PathFigure.Segments>
<PathSegmentCollection>
<ArcSegment Size="7.5,7.5" RotationAngle="90" IsLargeArc="False" SweepDirection="Clockwise" Point="25, -17.5" />
</PathSegmentCollection>
</PathFigure.Segments>
</PathFigure>
<PathFigure StartPoint="-25, -17.5">
<PathFigure.Segments>
<PathSegmentCollection>
<ArcSegment Size="7.5,7.5" RotationAngle="90" IsLargeArc="False" SweepDirection="Clockwise" Point="-17.5,-25" />
</PathSegmentCollection>
</PathFigure.Segments>
</PathFigure>
<PathFigure StartPoint="-17.5, 25">
<PathFigure.Segments>
<PathSegmentCollection>
<ArcSegment Size="7.5,7.5" RotationAngle="45" IsLargeArc="False" SweepDirection="Clockwise" Point="-25, 17.5" />
</PathSegmentCollection>
</PathFigure.Segments>
</PathFigure>
<PathFigure StartPoint="25, 17.5">
<PathFigure.Segments>
<PathSegmentCollection>
<ArcSegment Size="7.5,7.5" RotationAngle="45" IsLargeArc="False" SweepDirection="Clockwise" Point="17.5, 25" />
</PathSegmentCollection>
</PathFigure.Segments>
</PathFigure>
</PathFigureCollection>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>