-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ray.cs
124 lines (113 loc) · 3.79 KB
/
Ray.cs
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
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace raytraicing
{
public class Ray
{
public Point2DD FirstPoint;
public Point2DD DirectingVector;
public double Power;
public Point2DD CurPoint;
public int CurT;
public double Way;
public Ray(Point2DD _FirstPoint, Point2DD _DirectingVector, double _Power = 1.0)
{
FirstPoint = _FirstPoint;
DirectingVector = Useful.UVect(_DirectingVector);
Power = _Power;
CurPoint = new Point2DD(_FirstPoint);
CurT = 0;
Way = 0;
}
public Line ToLine()
{
return new Line(this);
}
public void NextCell(int XGR, int YGR, Listener Head)
{
int curX = (int)CurPoint.X / XGR;
int curY = (int)CurPoint.Y / YGR;
do
{
CurT++;
CurPoint.X = CurT * DirectingVector.X + FirstPoint.X;
CurPoint.Y = CurT * DirectingVector.Y + FirstPoint.Y;
} while (((int)CurPoint.X / XGR == curX) && ((int)CurPoint.Y / YGR == curY));
}
public void DrawRay(Graphics g, Pen pen)
{
g.DrawLine(pen, (int)FirstPoint.X, (int)FirstPoint.Y, (int)CurPoint.X, (int)CurPoint.Y);
g.Dispose();
}
public double GetDistance(Point2D Cur)
{
return this.ToLine().GetDistance(Cur);
}
public double GetLength()
{
return Useful.vect_length(CurPoint, FirstPoint);
}
public void ReNew(Rib CurRib)
{
Way += Useful.vect_length(CurPoint, FirstPoint);
DirectingVector = new Point2DD(DirectingVector.X - 2 * (DirectingVector.X * CurRib.Normal.X + DirectingVector.Y * CurRib.Normal.Y) * CurRib.Normal.X,
DirectingVector.Y - 2 * (DirectingVector.X * CurRib.Normal.X + DirectingVector.Y * CurRib.Normal.Y) * CurRib.Normal.Y);
FirstPoint = new Point2DD(CurPoint);
CurT = 0;
Power *= 1 - CurRib.Coef;
}
public void ReNew(Point2DD RibNormal, double Coef)
{
Way += Useful.vect_length(CurPoint, FirstPoint);
DirectingVector = new Point2DD(DirectingVector.X - 2 * (DirectingVector * RibNormal) * RibNormal.X,
DirectingVector.Y - 2 * (DirectingVector * RibNormal) * RibNormal.Y);
FirstPoint = new Point2DD(CurPoint);
CurT = 0;
Power *= 1 - Coef;
}
}
class Rays
{
public int Count;
public List<Ray> List;
public Rays(Point2DD _Position)
{
Count = 1;
List = new List<Ray>(Count);
Add(_Position, new Point2DD(Math.Cos(60 * Math.PI / 180), Math.Sin(60 * Math.PI / 180)));
}
public Rays(Point2DD _Position, int _Count)
{
Count = _Count;
List = new List<Ray>(Count);
for (int i = 0; i < Count; ++i)
Add(_Position, new Point2DD(Math.Cos(2 * Math.PI * i / Count), Math.Sin(2 * Math.PI * i / Count)));
}
public void Add(Point2DD _FirstPoint, Point2DD _DirectingVector, double _Power = 1.0)
{
List.Add(new Ray(_FirstPoint, _DirectingVector, _Power));
}
public Ray this[int index]
{
get
{
return List[index];
}
}
public int GetCount()
{
return List.Count;
}
public void Clear()
{
List.Clear();
}
}
}