728x90
반응형
728x170
▶ MainWindow.xaml
<Window x:Class="TestProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="800"
Height="600"
Title="1차 방정식 직선을 기준으로 대칭 포인트 구하기"
FontFamily="나눔고딕코딩"
FontSize="16">
<Grid Margin="10">
<Border
BorderBrush="Black"
BorderThickness="1">
<Canvas Name="canvas" />
</Border>
</Grid>
</Window>
728x90
▶ MainWindow.xaml.cs
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
namespace TestProject
{
/// <summary>
/// 메인 윈도우
/// </summary>
public partial class MainWindow : Window
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainWindow()
/// <summary>
/// 생성자
/// </summary>
public MainWindow()
{
InitializeComponent();
Loaded += Window_Loaded;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 윈도우 로드시 처리하기 - Window_Loaded(sender, e)
/// <summary>
/// 윈도우 로드시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Window_Loaded(object sender, RoutedEventArgs e)
{
double slope = 2 / 3d;
double yIntercept = 3;
Point lineStartPoint = new Point();
lineStartPoint.X = 0;
lineStartPoint.Y = slope * lineStartPoint.X + yIntercept;
Point lineEndPoint = new Point();
lineEndPoint.X = this.canvas.ActualWidth;
lineEndPoint.Y = slope * lineEndPoint.X + yIntercept;
Line line = new Line();
line.Stroke = Brushes.Gray;
line.StrokeThickness = 3;
line.X1 = lineStartPoint.X;
line.Y1 = lineStartPoint.Y;
line.X2 = lineEndPoint.X;
line.Y2 = lineEndPoint.Y;
this.canvas.Children.Add(line);
Point sourcePoint = new Point();
sourcePoint.X = 200;
sourcePoint.Y = 400;
Ellipse sourceEllipse = new Ellipse();
sourceEllipse.Fill = Brushes.Blue;
sourceEllipse.Width = 8;
sourceEllipse.Height = 8;
Canvas.SetLeft(sourceEllipse, sourcePoint.X - 4);
Canvas.SetTop (sourceEllipse, sourcePoint.Y - 4);
this.canvas.Children.Add(sourceEllipse);
Point symmetryPoint = GetSymmetryPoint(slope, yIntercept, sourcePoint);
Ellipse symmetryEllipse = new Ellipse();
symmetryEllipse.Fill = Brushes.Red;
symmetryEllipse.Width = 8;
symmetryEllipse.Height = 8;
Canvas.SetLeft(symmetryEllipse, symmetryPoint.X - 4);
Canvas.SetTop (symmetryEllipse, symmetryPoint.Y - 4);
this.canvas.Children.Add(symmetryEllipse);
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 대칭 포인트 구하기 - GetSymmetryPoint(slope, yIntercept, sourcePoint)
/// <summary>
/// 대칭 포인트 구하기
/// </summary>
/// <param name="slope">1차 방정식 선 기울기</param>
/// <param name="yIntercept">1차 방정식 선 Y 절편</param>
/// <param name="sourcePoint">소스 포인트</param>
/// <returns>대칭 포인트</returns>
private Point GetSymmetryPoint(double slope, double yIntercept, Point sourcePoint)
{
double slopeSquare = slope * slope;
double targetX = ((1 - slopeSquare) * sourcePoint.X + 2 * slope * sourcePoint.Y - 2 * slope * yIntercept) / (1 + slopeSquare);
double targetY = (2 * slope * sourcePoint.X - (1 - slopeSquare) * sourcePoint.Y + 2 * yIntercept) / (1 + slopeSquare);
return new Point(targetX, targetY);
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] ScaleTransform 엘리먼트 : 좌우대칭 반사 텍스트 만들기 (0) | 2020.09.07 |
---|---|
[C#/WPF] RotateTransform 클래스 : 텍스트 회전하기 (0) | 2020.09.07 |
[C#/WPF] ScaleTransform 엘리먼트 : 하강 문자(descender)가 포함된 텍스트 그림자 만들기 (0) | 2020.09.07 |
[C#/WPF] ScaleTransform 엘리먼트 : 텍스트 그림자 만들기 (0) | 2020.09.07 |
[C#/WPF] TextBox 엘리먼트 : 입력한 텍스트가 없는 경우 배경 메시지 보여주기 (0) | 2020.09.07 |
[C#/WPF] PathGeometry 클래스 : CreateFromGeometry 정적 메소드를 사용해 패스 지오메트리 구하기 (0) | 2020.09.06 |
[C#/WPF] LinearGradientBrush 엘리먼트 : 투명 패널 사용하기 (0) | 2020.09.06 |
[C#/WPF] FFMPEG을 사용해 동영상 재생하기 (0) | 2020.09.06 |
[C#/WPF] Storyboard 엘리먼트 : 마우스 위치에 따라 특정 엘리먼트 표시하기/숨기기 (0) | 2020.09.03 |
[C#/WPF] ControlTemplate 엘리먼트 : ScrollViewer 엘리먼트 정의하기 (0) | 2020.09.03 |
댓글을 달아 주세요