E0 = [ 0, 0, 1];
E1 = [ 1, 1, 0];
E2 = [-1, 1, 0];
E3 = [-1, -1, 0];
E4 = [ 1, -1, 0];
Pyramid.Z = E0(3);
Pyramid.Base = [min(E(:, 1)), max(E(:, 1)), min(E(:, 2)), max(E(:,2))]
P = rand(10000, 3) .* [2, 2, 1] - [1, 1, 0];
T = inPyramid(P, Pyramid);
P = P(T, :);
figure;
plot3(P(:,1), P(:,2), P(:,3), '.')
hold on
plot3(E0(1), E0(2), E0(3), 'ro');
plot3(E1(1), E1(2), E1(3), 'ro');
plot3(E2(1), E2(2), E2(3), 'ro');
plot3(E3(1), E3(2), E3(3), 'ro');
plot3(E4(1), E4(2), E4(3), 'ro');
xlabel('x')
ylabel('y')
zlabel('z')
function T = inPyramid(P, Pyramid)
S = Pyramid.Base .* (Pyramid.Z - P(:, 3)) / Pyramid.Z;
T = (P(:, 3) >= 0 & P(:, 3) <= Pyramid.Z) & ...
(P(:, 1) >= S(:, 1) & P(:, 1) <= S(:, 2)) & ...
(P(:, 2) >= S(:, 3) & P(:, 2) <= S(:, 4));
end
0 Comments
Sign in to comment.