how to create shape on xy surface?
3 次查看(过去 30 天)
显示 更早的评论
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:
- create the shape for the each case
- lay the shapes one on another
- 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 个评论
Les Beckham
2023-11-14
编辑:Les Beckham
2023-11-14
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), '.')
采纳的回答
Chunru
2023-11-17
编辑:Chunru
2023-11-20
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]
min(abs(S.H)), max(abs(S.H))
whos
% create the shape for the each case
n = length(S.H)
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 个评论
Chunru
2023-11-20
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)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!