-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathImpactPointFind.m
106 lines (96 loc) · 2.73 KB
/
ImpactPointFind.m
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
function [ImpactPoint, t, wall, wallvector]=ImpactPointFind(Source,Ray,L,W,H)
% find the new impact point
% author@mhrex(Hao MA) Nov.14,2014
c = physconst('LightSpeed');
while(1)
% north wall
n_surface = [1,0,0];
temp = dot(n_surface,Ray);
if (temp>0)
d = L-Source(1);
k = d/temp;
impact_temp=Source+k*Ray;
if ((impact_temp(2)<=W) && (impact_temp(2)>=0) && (impact_temp(3)<=H) && (impact_temp(3)>=0))
ImpactPoint = impact_temp;
t=k/c;
wall = 'north';
wallvector = [-1,0,0];
break;
end
end
% south wall
n_surface = [-1,0,0];
temp = dot(n_surface,Ray);
if (temp>0)
d = Source(1);
k = d/temp;
impact_temp=Source+k*Ray;
if ((impact_temp(2)<=W) && (impact_temp(2)>=0) && (impact_temp(3)<=H) && (impact_temp(3)>=0))
ImpactPoint = impact_temp;
t=k/c;
wall = 'south';
wallvector = [1,0,0];
break;
end
end
% west wall
n_surface = [0,1,0];
temp = dot(n_surface,Ray);
if (temp>0)
d = W-Source(2);
k = d/temp;
impact_temp=Source+k*Ray;
if ((impact_temp(1)<=L) && (impact_temp(1)>=0) && (impact_temp(3)<=H) && (impact_temp(3)>=0))
ImpactPoint = impact_temp;
t=k/c;
wall = 'west';
wallvector = [0,-1,0];
break;
end
end
% east wall
n_surface = [0,-1,0];
temp = dot(n_surface,Ray);
if (temp>0)
d = Source(2);
k = d/temp;
impact_temp=Source+k*Ray;
if ((impact_temp(1)<=L) && (impact_temp(1)>=0) && (impact_temp(3)<=H) && (impact_temp(3)>=0))
ImpactPoint = impact_temp;
t=k/c;
wall = 'east';
wallvector = [0,1,0];
break;
end
end
% ceiling wall
n_surface = [0,0,1];
temp = dot(n_surface,Ray);
if (temp>0)
d = H-Source(3);
k = d/temp;
impact_temp=Source+k*Ray;
if ((impact_temp(1)<=L) && (impact_temp(1)>=0) && (impact_temp(2)<=W) && (impact_temp(2)>=0))
ImpactPoint = impact_temp;
t=k/c;
wall = 'ceiling';
wallvector = [0,0,-1];
break;
end
end
% floor wall
n_surface = [0,0,-1];
temp = dot(n_surface,Ray);
if (temp>0)
d = Source(3);
k = d/temp;
impact_temp=Source+k*Ray;
if ((impact_temp(1)<=L) && (impact_temp(1)>=0) && (impact_temp(2)<=W) && (impact_temp(2)>=0))
ImpactPoint = impact_temp;
t=k/c;
wall = 'floor';
wallvector = [0,0,1];
break;
end
end
end