Calculate centroid and length of a rectangular shape

Hi,
I would like to obtain the distance with respect to the centriod (both distances 97.2 and 152.78) as shown in the figure. The centroid already obtained by the following commands (255.55) but I would like then to calculate the distance 247.22-(100+50)= 97.2
and for the bottom equal to (300+100)-255.55=152.78
So I would like my output to be =[97.2 247.22 152.78]
I would like to have a commands which works for different number, hope you get the idea nd could help me
function [Ybar]=y_bar_calculations(l)
l=[50 200 300];
l(1:length(l))=l(length(l):-1:1);
for i=1:length(l)
if i==1
Ybar_Pre(i)= l(i)/2;
else
Ybar_Pre(i) = sum(l(1:i-1)) + l(i)/2;
end
end
Ybar(1:length(l),1)= Ybar_Pre(length(l):-1:1);
c=247.22
% OUTPUT SHOULD BE [97.2 247.22 152.78]
end

9 comentarios

darova
darova el 21 de Abr. de 2020
Here is the first step
function [Ybar]=y_bar_calculations(l)
l=[50 200 300];
l(1:length(l))=l(length(l):-1:1);
for i=1:length(l)
if i==1
Ybar_Pre(i)= l(i)/2;
else
Ybar_Pre(i) = sum(l(1:i-1)) + l(i)/2;
end
end
Ybar(1:length(l),1)= Ybar_Pre(length(l):-1:1);
c=247.22
% OUTPUT SHOULD BE [97.2 247.22 152.78]
end
Ali Tawfik
Ali Tawfik el 21 de Abr. de 2020
Hi, thanks for your comment,
I added it. wish you could help !
Rik
Rik el 21 de Abr. de 2020
I have no clue which lengths you're trying to subtract from where. If you replace every length by a letter, what would you have then? Wouldn't that already be what you need?
Ali Tawfik
Ali Tawfik el 21 de Abr. de 2020
HI Rik,
Thanks for your reply.
As shown in the above figure: If I have 3 different pieces , So I would like to have 3 different numbers (included the one I already obtained )
I mean, I would like to calculate the distance from 247.2 to the top ?? which is half the length of the middle part added to the total length of the top part
and for the bottom part will be half the length of the middle part added to the total length of the BOTTOM part
so the output will be [top distance to 247.2, 247.2, bottom distance to 247.2]
Hope now, it more clear
Looking forward to your answer
Thanks in advance
Rik
Rik el 21 de Abr. de 2020
What are your exact inputs and what output do you want? Are all the distances shown in your question the input? And what is the origin of your coordinate system?
Ali Tawfik
Ali Tawfik el 21 de Abr. de 2020
Thanks again for your answer.
I really need this !!!
All the input are marked in blue color, the origin is 247.22
So I would like my out out to be = [2.8 247.22 252.78]
darova
darova el 22 de Abr. de 2020
Rik ? Can you please help?
Rik
Rik el 22 de Abr. de 2020
The origin is not a number, it is a position.
Now define your inputs explicitly: mark points with letters and list all letter-to-letter distance you know as input. Then point out what you need as output, putting additional letters if needed.
Now that you have your geometric problem defined you can start writing the algebra: which values do you need subtract from which other value?
Only then can you write it as a function.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 20 de Abr. de 2020

Comentada:

Rik
el 22 de Abr. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by