-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShape.cs
More file actions
155 lines (140 loc) · 3.98 KB
/
Shape.cs
File metadata and controls
155 lines (140 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
using System.Xml.Serialization;
namespace OOPLab2
{
public class Poligon
{
public virtual double Area
{
get
{
double sum = 0;
for (int i = 0; i < Points.Count; ++i)
{
sum += this[i].X * this[i - 1].Y - this[i - 1].X * this[i].Y;
}
return sum;
}
}
public List<Vector> Points;
public Vector this[int n]
{
get
{
if (n >= 0 && n < Points.Count)
{
return Points[n];
}
else if (n < 0)
{
return Points[Points.Count + n];
}
else
{
return Points[n % Points.Count];
}
}
set
{
if (n >= 0 && n < Points.Count)
{
Points[n] = value;
}
else if (n < 0)
{
Points[Points.Count + n] = value;
}
else
{
Points[n % Points.Count] = value;
}
}
}
internal virtual Vector Center
{
get
{
Vector sum = Vector.Zero;
for (int i = 0; i < Points.Count; ++i)
{
sum += this[i];
}
return sum / Points.Count;
}
}
internal Vector Normal()
{
Vector a, b, c;
a = this[0];
b = this[1];
c = this[2];
Vector ab, bc;
ab = a - b;
bc = b - c;
return Vector.CrossProduct(ab,bc).Norm;
}
internal Poligon(List<Vector> Points)
{
this.Points = Points;
}
internal Poligon()
{
}
//зміна полігону матрицею
public static Poligon operator *(Matrix m, Poligon p)
{
List<Vector> Points=new List<Vector>();
for (int i = 0;i< p.Points.Count; i++)
{
Points.Add(m*p.Points[i]);
}
return new Poligon(Points);
}
}
public class RegularShape : Poligon
{
double radius;
internal override Vector Center
{
get;
}
public override double Area
{
get
{
return 0.5 * Points.Count * radius * radius * Math.Sin(Math.PI * 2 / Points.Count);
}
}
public static RegularShape operator *(Matrix m, RegularShape s)
{
List<Vector> Points = new List<Vector>();
for (int i = 0; i < s.Points.Count; i++)
{
Points.Add(m * s.Points[i]);
}
return new RegularShape(Points,s.radius,s.Center);
}
private RegularShape(List<Vector> Points,double R,Vector Center) :base(Points)
{
radius=R;
this.Center = Center;
}
//конструктор 2
public RegularShape(double R, int CountPoints) : this(R, CountPoints, Vector.Zero) { }
//конструктор
public RegularShape(double R, int CountPoints, Vector center)
{
Center=center;
if (CountPoints < 2) return;
Points = new List<Vector>(capacity: CountPoints);
radius = R;
//далі заповнюємо ліст координатами
double angle = Math.PI * 2 / CountPoints;
double sin, cos;
for (int i = 0; i < CountPoints; ++i)
{
(sin, cos) = Math.SinCos(angle * i);
Points.Add(new Vector(R * sin, R * cos, 0));
}
}
}
}