how to create shape on xy surface?

I need to calculate the area of shapes (parallelograms) that lay on one another. Their width is equal to 2. One of the angles (H) and the 'length' are variables (attached). So at the first I have created the list of the tasks:
  1. create the shape for the each case
  2. lay the shapes one on another
  3. and calculate the created shape's area
I have no idea how to do it, but looking into different options.
You are welcome to help with any of 3 tasks or with all of them.
I came accross with this
but I am still far away from understanding how to handle my task.
If it is simple for you, code it please, otherwise any hints and links to similar questions will be very helpful.
Thanks in advance.

2 Comments

Can you explain (preferably with a sketch) what you mean by "angles" and "length"?
Also, more than half of your length values are zero (see below).
S = load('variable.mat');
plot(S.H, '.')
hold on
grid on
plot(S.length(S.length ~= 0), '.')
Hi, thanks for the reply
sorry for the inconvinience, this will sort the data:
angle=angle(length>0);
length=length(length>0);
so, the coordinates of the baseline (width at the bottom) stays the same.
thanks in advance

Sign in to comment.

 Accepted Answer

Chunru
Chunru on 17 Nov 2023
Edited: Chunru on 20 Nov 2023
websave("variable.mat", "https://www.mathworks.com/matlabcentral/answers/uploaded_files/1538662/variable.mat");
S = load('variable.mat');
% idx = S.H ~= 0 & S.length ~=0;
idx = S.length ~=0;
% Do computations only on the nonzero length and angle
S.H = 90 + S.H(idx)'; % check your definition of angle
S.length = S.length(idx)';
[S.H S.length]
ans = 108×2
23.1578 12.4611 24.4078 6.2578 25.6578 4.1901 26.9078 3.1563 28.1578 2.5361 29.4078 2.1227 30.6578 1.8275 31.9078 1.6062 33.1578 1.4341 34.4078 1.2966
min(abs(S.H)), max(abs(S.H))
ans = single 23.1578
ans = single 156.9078
whos
Name Size Bytes Class Attributes S 1x1 1200 struct ans 1x1 4 single cmdout 1x33 66 char idx 1x289 289 logical
% create the shape for the each case
n = length(S.H)
n = 108
w = 2;
S.X = [zeros(n,1) 2+zeros(n,1) S.length.*cosd(S.H)+2 S.length.*cosd(S.H)];
S.Y = [zeros(n,1) zeros(n,1) S.length.*sind(S.H) S.length.*sind(S.H)];
% lay the shapes one on another
figure
plot(S.X(:, [1:end 1])', S.Y(:, [1:end 1])') % plot all shapes
% plot shapes evry other 10
figure
plot(S.X(1:10:end, [1:end 1])', S.Y(1:10:end, [1:end 1])')
axis([-2 4 0 2])
% and calculate the created shape's area
S.A = abs(S.length.*w.*sind(S.H));
figure;
plot(S.A);
xlabel("Shape Index"); ylabel("Area")

7 Comments

I have the same problem, the values of 'angle' are from 20 to 90 degrees, but it is the same in all plotted shapes
The angle range from +/-0 - 67 deg. What do you mean "same in all plotted shapes"?
Hi,
my bad, you are right the range is from 0 to 67. In your plot, only the size of the figures change, but expected something like this:
I just realized that at zero angle the shape should be rectangle. And the problem was that angle=90+H. Sorry for this, I understood it only now.
Thanks.
PS. I still don't know how to do it.
See the updated.
That is great.
Please, tell me what shape index is.
I'd rather have a one value for the total area, so shall I sum S.A?
Thank you.
You have 108 shapes with length>0. The shape index (i from 1 to 108) is the reference to the i-th shape you have.
You can sum all the area by: sum(S.A)

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2021a

Tags

Community Treasure Hunt

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

Start Hunting!