H
Hany Metry
Guest
Hi,
How to write a code to calculate the area and moment of inertia about both axis of any shape by knowing a coordinates.
I wrote the below code to calculate the area and both moment of inertia by dividing the shape into triangles but I find that some triangles should be added and some triangles should be subtracted and I can't write the correct condition to know which triangles should be added and which triangles should be subtracted.
Area = 0.0
IIx = 0.0
IIy = 0.0
For q = 0 To Numcoor - 2
If condition not known Then
Area = Area - (Xcoor(q) * Ycoor(q + 1) - Ycoor(q) * Xcoor(q + 1)) / 2
IIx = IIx - ((Ycoor(q) ^ 2 + Ycoor(q) * Ycoor(q + 1) + Ycoor(q + 1) ^ 2) / 12) * (Xcoor(q) * Ycoor(q + 1) - Ycoor(q) * Xcoor(q + 1))
IIy = IIy - ((Xcoor(q) ^ 2 + Xcoor(q) * Xcoor(q + 1) + Xcoor(q + 1) ^ 2) / 12) * (Xcoor(q) * Ycoor(q + 1) - Ycoor(q) * Xcoor(q + 1))
Else
Area = Area + (Xcoor(q) * Ycoor(q + 1) - Ycoor(q) * Xcoor(q + 1)) / 2
IIx = IIx + ((Ycoor(q) ^ 2 + Ycoor(q) * Ycoor(q + 1) + Ycoor(q + 1) ^ 2) / 12) * (Xcoor(q) * Ycoor(q + 1) - Ycoor(q) * Xcoor(q + 1))
IIy = IIy + ((Xcoor(q) ^ 2 + Xcoor(q) * Xcoor(q + 1) + Xcoor(q + 1) ^ 2) / 12) * (Xcoor(q) * Ycoor(q + 1) - Ycoor(q) * Xcoor(q + 1))
End If
hh = q
Next
If condition not known Then
Area = Area - (Xcoor(hh + 1) * Ycoor(0) - Ycoor(hh + 1) * Xcoor(0)) / 2
IIx = IIx - ((Ycoor(hh + 1) ^ 2 + Ycoor(hh + 1) * Ycoor(0) + Ycoor(0) ^ 2) / 12) * (Xcoor(hh + 1) * Ycoor(0) - Ycoor(hh + 1) * Xcoor(0))
IIy = IIy - ((Xcoor(hh + 1) ^ 2 + Xcoor(hh + 1) * Xcoor(0) + Xcoor(0) ^ 2) / 12) * (Xcoor(hh + 1) * Ycoor(0) - Ycoor(hh + 1) * Xcoor(0))
Else
Area = Area + (Xcoor(hh + 1) * Ycoor(0) - Ycoor(hh + 1) * Xcoor(0)) / 2
IIx = IIx + ((Ycoor(hh + 1) ^ 2 + Ycoor(hh + 1) * Ycoor(0) + Ycoor(0) ^ 2) / 12) * (Xcoor(hh + 1) * Ycoor(0) - Ycoor(hh + 1) * Xcoor(0))
IIy = IIy + ((Xcoor(hh + 1) ^ 2 + Xcoor(hh + 1) * Xcoor(0) + Xcoor(0) ^ 2) / 12) * (Xcoor(hh + 1) * Ycoor(0) - Ycoor(hh + 1) * Xcoor(0))
End If
Area = Math.Abs(Area)
IIx = Math.Abs(IIx)
IIy = Math.Abs(IIy)
If you try to find the condition you will find the condition is different for L shape than for I shape.
Kind Regards,
Hany Metry
Continue reading...
How to write a code to calculate the area and moment of inertia about both axis of any shape by knowing a coordinates.
I wrote the below code to calculate the area and both moment of inertia by dividing the shape into triangles but I find that some triangles should be added and some triangles should be subtracted and I can't write the correct condition to know which triangles should be added and which triangles should be subtracted.
Area = 0.0
IIx = 0.0
IIy = 0.0
For q = 0 To Numcoor - 2
If condition not known Then
Area = Area - (Xcoor(q) * Ycoor(q + 1) - Ycoor(q) * Xcoor(q + 1)) / 2
IIx = IIx - ((Ycoor(q) ^ 2 + Ycoor(q) * Ycoor(q + 1) + Ycoor(q + 1) ^ 2) / 12) * (Xcoor(q) * Ycoor(q + 1) - Ycoor(q) * Xcoor(q + 1))
IIy = IIy - ((Xcoor(q) ^ 2 + Xcoor(q) * Xcoor(q + 1) + Xcoor(q + 1) ^ 2) / 12) * (Xcoor(q) * Ycoor(q + 1) - Ycoor(q) * Xcoor(q + 1))
Else
Area = Area + (Xcoor(q) * Ycoor(q + 1) - Ycoor(q) * Xcoor(q + 1)) / 2
IIx = IIx + ((Ycoor(q) ^ 2 + Ycoor(q) * Ycoor(q + 1) + Ycoor(q + 1) ^ 2) / 12) * (Xcoor(q) * Ycoor(q + 1) - Ycoor(q) * Xcoor(q + 1))
IIy = IIy + ((Xcoor(q) ^ 2 + Xcoor(q) * Xcoor(q + 1) + Xcoor(q + 1) ^ 2) / 12) * (Xcoor(q) * Ycoor(q + 1) - Ycoor(q) * Xcoor(q + 1))
End If
hh = q
Next
If condition not known Then
Area = Area - (Xcoor(hh + 1) * Ycoor(0) - Ycoor(hh + 1) * Xcoor(0)) / 2
IIx = IIx - ((Ycoor(hh + 1) ^ 2 + Ycoor(hh + 1) * Ycoor(0) + Ycoor(0) ^ 2) / 12) * (Xcoor(hh + 1) * Ycoor(0) - Ycoor(hh + 1) * Xcoor(0))
IIy = IIy - ((Xcoor(hh + 1) ^ 2 + Xcoor(hh + 1) * Xcoor(0) + Xcoor(0) ^ 2) / 12) * (Xcoor(hh + 1) * Ycoor(0) - Ycoor(hh + 1) * Xcoor(0))
Else
Area = Area + (Xcoor(hh + 1) * Ycoor(0) - Ycoor(hh + 1) * Xcoor(0)) / 2
IIx = IIx + ((Ycoor(hh + 1) ^ 2 + Ycoor(hh + 1) * Ycoor(0) + Ycoor(0) ^ 2) / 12) * (Xcoor(hh + 1) * Ycoor(0) - Ycoor(hh + 1) * Xcoor(0))
IIy = IIy + ((Xcoor(hh + 1) ^ 2 + Xcoor(hh + 1) * Xcoor(0) + Xcoor(0) ^ 2) / 12) * (Xcoor(hh + 1) * Ycoor(0) - Ycoor(hh + 1) * Xcoor(0))
End If
Area = Math.Abs(Area)
IIx = Math.Abs(IIx)
IIy = Math.Abs(IIy)
If you try to find the condition you will find the condition is different for L shape than for I shape.
Kind Regards,
Hany Metry
Continue reading...