# Cutting Polyshape using Y function

6 Ansichten (letzte 30 Tage)
Emmeirrt am 21 Mai 2022
Beantwortet: Pavan Sahith am 16 Dez. 2023
I need to seperate final object using Y function
Both final object and Y function will be determined by user but i added random input so you dont have to deal with that
There is the simplified code
x1:0
x2:6
y1:0
y2:8
RX1=-190
RX2=149
RY1=111
a=1
f=0
CC=[149,111]
rectangle= polyshape([RX1,RX1,RX2,RX2],[0,RY1,RY1,0]);
triangle = polyshape([RX1,0,RX1],[(RY1-((10*a)+h)),RY1,RY1]);
cirle = polybuffer(CC,'points',((10*a)+f));
cut = union(cirle,triangle);
final = subtract(rectangle,cut);
plot(final)
x1=A(1,1);
y1=A(1,2);
x2=A(2,1);
y2=A(2,2);
m=((y2-y1)/(x2-x1));
Y =@(X) (m*(X-x1)+y1);
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Antworten (1)

Pavan Sahith am 16 Dez. 2023
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.
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Elementary Polygons finden Sie in Help Center und File Exchange

R2021b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by