I am having troubles trying to run the following code. It is meant to calculate a series of rays reflections inside a closed room (2D).
Collision[] is a function that returns the intersection point (ray hit) with the closest object/wall.
p = {10,0} is the source location.
line is a list contains {a,b} where y=ax+b is the ray's line equation.
Code:
path[line_, k_] := (
p = {10, 0};
l = {p};
line1 = line;
For[i = 1, i <= k, i = i + 1,
p = collision[line1, p];
AppendTo[l, p];
If[9.5 <= p[[1]] <= 10.5 && p[[2]] == 15 , Break[],
line1 = {-1/line1[[1]], p[[2]] - -1/line1[[1]]*p[[1]]}]
]
l
)
Calling this function with the needed parameters:
path[{1, -10}, 2]
Returns the output:
{{10 Null, 0}, {20 Null, 10 Null}, {0, 30 Null}}
While the expected output is supposed to be:
{{10, 0}, {20, 10}, {0, 30}}
Where did I go wrong?
Any help will be appreciated!
p[[2]] - -1/line1[[1]]probably you mean a single-? – rhermans May 15 '17 at 16:58Forloop returnsNullthat you then multiply with the listl. Did you mean; lafter theFor? – rhermans May 15 '17 at 17:07