I have a logical square array such that a value of 1 signifies that light is allowed to pass through the array at those points, and a value of 0 means that light is blocked.
How do I create a triangular aperture shape in this array? I am genuinely stumped and have racked my brain quite a bit but cannot come up with a solution.
Consider the logical array as the result of many evaluations of a function, with input
x
andy
. Then your job is to create the function that returnstrue
for points inside the triangle, andfalse
for points outside.And what would that function be? For that, see the many answers provided on this (unfortunately and inappropriately closed question): How to determine if a point is in a 2D triangle?
Or, since this is MATLAB, use the more general (and therefore less performant)
inpolygon
. Express the triangle as a list of x coordinates and a list of y coordinates.Then, test all your points by generating a grid of x and y over your logical matrix, and pass all those points to
inpolygon
.The following is untested: