你这个还有不确定因素啊,如:线的长度,也包括startpoint和endpoint,具体计算的时候用三角函数,很简单的。
补充在上面了:
用矩阵旋转的方式实现。
1 void Main()
2 {
3 //假设的两个点
4 Vector2 startPoint = new Vector2(1, 60);
5 Vector2 endPoint = new Vector2(1, -60);
6
7 //中点坐标
8 Vector2 centerPoint=new Vector2((endPoint.X+startPoint.X)/2,(endPoint.Y+startPoint.Y)/2);
9
10 //CreateRotation参数是弧度
11 Matrix m= Matrix.CreateRotation(3.14159265479f/2);
12 //各按他们的中点旋转90度
13 Vector2 ntStartpoint= Vector2.Transform(new Vector2(startPoint.X-centerPoint.X,startPoint.Y-centerPoint.Y), m);
14 Vector2 ntEndpoint= Vector2.Transform(new Vector2(endPoint.X-centerPoint.X,endPoint.Y-centerPoint.Y), m);
15
16 //要求的两个点
17 Vector2 newStartPoint=new Vector2(ntStartpoint.X+centerPoint.X,ntStartpoint.Y+centerPoint.Y);
18 Vector2 newEndPoint=new Vector2(ntEndpoint.X+centerPoint.X,ntEndpoint.Y+centerPoint.Y);
19 }
20
21 public struct Matrix
22 {
23 public float M11;
24 public float M12;
25 public float M13;
26 public float M14;
27 public float M21;
28 public float M22;
29 public float M23;
30 public float M24;
31 public float M31;
32 public float M32;
33 public float M33;
34 public float M34;
35 public float M41;
36 public float M42;
37 public float M43;
38 public float M44;
39
40 public static Matrix CreateRotation(float radians)
41 {
42 Matrix matrix;
43 float num2 = (float)Math.Cos((double)radians);
44 float num = (float)Math.Sin((double)radians);
45 matrix.M11 = num2;
46 matrix.M12 = num;
47 matrix.M13 = 0f;
48 matrix.M14 = 0f;
49 matrix.M21 = -num;
50 matrix.M22 = num2;
51 matrix.M23 = 0f;
52 matrix.M24 = 0f;
53 matrix.M31 = 0f;
54 matrix.M32 = 0f;
55 matrix.M33 = 1f;
56 matrix.M34 = 0f;
57 matrix.M41 = 0f;
58 matrix.M42 = 0f;
59 matrix.M43 = 0f;
60 matrix.M44 = 1f;
61 return matrix;
62 }
63 }
64
65 public struct Vector2
66 {
67 public float X;
68 public float Y;
69
70 public Vector2(float x, float y)
71 {
72 this.X = x;
73 this.Y = y;
74 }
75
76 public static Vector2 Transform(Vector2 position, Matrix matrix)
77 {
78 Vector2 vector;
79 float num2 = ((position.X * matrix.M11) + (position.Y * matrix.M21)) + matrix.M41;
80 float num = ((position.X * matrix.M12) + (position.Y * matrix.M22)) + matrix.M42;
81 vector.X = num2;
82 vector.Y = num;
83 return vector;
84 }
85 }