markus / KCOM / Common / MathHelper.cs @ f3ab410f
이력 | 보기 | 이력해설 | 다운로드 (1.58 KB)
1 | 8de55603 | taeseongkim | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.Linq; |
||
4 | using System.Text; |
||
5 | using System.Threading.Tasks; |
||
6 | using System.Windows; |
||
7 | using System.Windows.Media; |
||
8 | |||
9 | namespace KCOM.Common |
||
10 | { |
||
11 | public static class MathHelper |
||
12 | { |
||
13 | |||
14 | public static Point RotatePoint(Point p1, Point p2, double angle) |
||
15 | { |
||
16 | |||
17 | double radians = ConvertToRadians(angle); |
||
18 | double sin = Math.Sin(radians); |
||
19 | double cos = Math.Cos(radians); |
||
20 | |||
21 | // Translate point back to origin |
||
22 | p1.X -= p2.X; |
||
23 | p1.Y -= p2.Y; |
||
24 | |||
25 | // Rotate point |
||
26 | double xnew = p1.X * cos - p1.Y * sin; |
||
27 | double ynew = p1.X * sin + p1.Y * cos; |
||
28 | |||
29 | // Translate point back |
||
30 | Point newPoint = new Point((int)xnew + p2.X, (int)ynew + p2.Y); |
||
31 | return newPoint; |
||
32 | } |
||
33 | |||
34 | public static double ConvertToRadians(double angle) |
||
35 | { |
||
36 | f3ab410f | taeseongkim | return (Math.PI / 360) * angle; |
37 | 8de55603 | taeseongkim | } |
38 | |||
39 | f3ab410f | taeseongkim | public static Rect RotateRect(Rect rect,Point Center,double angle) |
40 | 8de55603 | taeseongkim | { |
41 | f3ab410f | taeseongkim | Rect rotateRect = rect; |
42 | 8de55603 | taeseongkim | |
43 | f3ab410f | taeseongkim | var centerPoint = new Point(rect.X,rect.Y); |
44 | var rotationCenter = RotatePoint(centerPoint, Center, angle); |
||
45 | 8de55603 | taeseongkim | |
46 | f3ab410f | taeseongkim | if (angle == 270 || angle == 90) |
47 | { |
||
48 | rotateRect = new Rect(0,0, rect.Height, rect.Width); |
||
49 | } |
||
50 | else |
||
51 | { |
||
52 | rotateRect = new Rect(0,0, rect.Width, rect.Height); |
||
53 | } |
||
54 | 8de55603 | taeseongkim | |
55 | f3ab410f | taeseongkim | rotateRect.X = rotationCenter.X; |
56 | rotateRect.Y = rotationCenter.Y; |
||
57 | 8de55603 | taeseongkim | |
58 | f3ab410f | taeseongkim | return rotateRect; |
59 | 8de55603 | taeseongkim | } |
60 | } |
||
61 | } |