Hello,
As per my understanding, you have a polyshape and want to separate the 'final' object using a 'Y' function.
To achieve that in MATLAB you can generate the curve using the user-provided function and then cut the polyshape using “intersect” or “subtract”.
Refer to this sample code which defines a rectangle and a 'Y' function, creates a polyshape for the region above the 'Y' function, and then finds the intersection between the rectangle and the region to obtain the 'final' shape.
% Define rectangle and Y function
RX1 = -190;
RX2 = 149;
RY1 = 111;
rectangle = polyshape([RX1, RX1, RX2, RX2], [0, RY1, RY1, 0]);
Y = @(X) 0.5*X + 50;
% Create polyshape for region above Y function
x = linspace(RX1, RX2, 100);
y = Y(x);
% Intersect rectangle and region
region = polyshape([x, fliplr(x)], [y, ones(size(y))*max(rectangle.Vertices(:,2))])
final = intersect(rectangle, region);
% difference of two polyshape objects.
final1 = subtract(rectangle, region);
% Plot result
plot(final)
plot(final1)
The “fliplr” function is used to flip the order of the elements in an array from left to right.
In this code, it's used to create a closed polygon for the region above the ‘Y’ function by concatenating the original ‘x’ values with their reversed order.
Please refer to the MathWorks documentation to know more about