markus / KCOM / Common / MathHelper.cs @ f3ab410f
이력 | 보기 | 이력해설 | 다운로드 (1.58 KB)
1 |
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 |
return (Math.PI / 360) * angle; |
37 |
} |
38 |
|
39 |
public static Rect RotateRect(Rect rect,Point Center,double angle) |
40 |
{ |
41 |
Rect rotateRect = rect; |
42 |
|
43 |
var centerPoint = new Point(rect.X,rect.Y); |
44 |
var rotationCenter = RotatePoint(centerPoint, Center, angle); |
45 |
|
46 |
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 |
|
55 |
rotateRect.X = rotationCenter.X; |
56 |
rotateRect.Y = rotationCenter.Y; |
57 |
|
58 |
return rotateRect; |
59 |
} |
60 |
} |
61 |
} |