Help wanted. Python script for second moment of area

Post here if you have a FreeCAD-related job to offer to the FreeCAD community. This can include programming or modeling.
ajarivas72
Posts: 6
Joined: Sun Sep 11, 2016 10:35 pm

Help wanted. Python script for second moment of area

Postby ajarivas72 » Sun Jan 21, 2018 1:30 am

Hello

I am looking for a Python script that computes the second moment of area of a surface.

I need the second moment of area to compute the bending stress with the formula:

S = M * y / Iyy

where

M = bending moment
y : distance from the center of area
Iyy: second moment of area

The quantity I need is Iyy

Example:

For a rectangle of height "h" and base "b", the moment of area with respect to the center of mass is:

Iyy = b * h^3 / 12

The code must compute the Iyy correctly having a surface as an input to the script. The programmer must show several examples proving the correctness of her/his code and send the price to pay for her/his code.

We must agree to price, delivery time, and all the pertinent details.

Best regards.

Alejandro
UR_
Posts: 432
Joined: Tue Jan 03, 2017 8:42 pm

Re: Help wanted. Python script for second moment of area

Postby UR_ » Sun Jan 21, 2018 12:13 pm

This is really not a big task.
Please see this quick'n'dirty example. It's for free :lol:


Macro:

Code: Select all

import math

obj = App.getDocument("test_face").getObject("DWire")
shp = App.getDocument("test_face").getObject("DWire").Shape


MoI = shp.MatrixOfInertia
Ixx = MoI.A11
Iyy = MoI.A22
Izz = MoI.A33


Area = shp.Area
CoM = shp.CenterOfMass


Ix = shp.StaticMoments[0]
Iy = shp.StaticMoments[1]
Iz = shp.StaticMoments[2]


Ixxtrans = Ixx + Area * pow(CoM.x, 2.)
Iyytrans = Iyy + Area * pow(CoM.y, 2.)
Izztrans = Izz + Area * pow(CoM.z, 2.)



print "area ", Area
print "center ", CoM.x, " ", CoM.y, " ", CoM.z
print "staticmoments ", Ix, " ", Iy, " ", Iz
print "Inertia about [Gx,Gy,Gz] ", Ixx, " ", Iyy, " ", Izz
print "Inertia about [0,0,0] ", Ixxtrans, " ", Iyytrans, " ", Izztrans

Inertia.FCMacro
(718 Bytes) Downloaded 6 times
screenshot translated circle.png
screenshot translated circle.png (60.2 KiB) Viewed 1084 times
tree.png
tree.png (4.84 KiB) Viewed 1084 times

File:
test face.FCStd
(5.12 KiB) Downloaded 5 times

Done with:
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.13005 (Git)
Build type: Release
Branch: master
Hash: 29533320fc514029f3ce1af6bbf53cc03fb93049
Python version: 2.7.8
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.1.0
Locale: German/Germany (de_DE)
mario52
Posts: 2224
Joined: Wed May 16, 2012 2:13 pm

Re: Help wanted. Python script for second moment of area

Postby mario52 » Mon Jan 22, 2018 5:17 pm

hi UR_

same result with Macro_FCInfo

interesting your macro

i replace your two first line with (for use directly with object selected)

Code: Select all

#obj = App.getDocument("test_face").getObject("DWire")
#shp = App.getDocument("test_face").getObject("DWire").Shape

shp = FreeCADGui.Selection.getSelection()[0].Shape

I can add these code lines to my macro ?

Code: Select all

print "staticmoments ", Ix, " ", Iy, " ", Iz
print "Inertia about [0,0,0] ", Ixxtrans, " ", Iyytrans, " ", Izztrans
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets. My macros on Gist.github
ajarivas72
Posts: 6
Joined: Sun Sep 11, 2016 10:35 pm

Re: Help wanted. Python script for second moment of area

Postby ajarivas72 » Sat Jan 27, 2018 5:28 pm

UR_ and mario52

I thank you very much.
ajarivas72
Posts: 6
Joined: Sun Sep 11, 2016 10:35 pm

Re: Help wanted. Python script for second moment of area

Postby ajarivas72 » Sun Jan 28, 2018 7:41 am

UR_

Hello.

How do you create DWire object from the Sketch in your file ?
chrisb
Posts: 7293
Joined: Tue Mar 17, 2015 9:14 am

Re: Help wanted. Python script for second moment of area

Postby chrisb » Sun Jan 28, 2018 8:29 am

In Draft workbench is a tool DraftToSketch which converts in both directions depending on the selected input.
ajarivas72
Posts: 6
Joined: Sun Sep 11, 2016 10:35 pm

Re: Help wanted. Python script for second moment of area

Postby ajarivas72 » Sun Jan 28, 2018 9:00 am

chrisb

Thanks a lot. It worked beautifully
chrisb
Posts: 7293
Joined: Tue Mar 17, 2015 9:14 am

Re: Help wanted. Python script for second moment of area

Postby chrisb » Sun Jan 28, 2018 9:58 am

ajarivas72 wrote:
Sun Jan 28, 2018 9:00 am
Thanks a lot. It worked beautifully
You're welcome. I use it usually in the other direction to convert from svg files to sketches.
lukassturm
Posts: 3
Joined: Fri Mar 02, 2018 3:18 pm
Location: Darmstadt/Germany

Re: Help wanted. Python script for second moment of area

Postby lukassturm » Tue Mar 13, 2018 1:37 pm

Hello forum, I am still really new to FC but I already spent lots of time using it.
Specifically I spent lots of hours on the problem of computing the 2nd moment of area (german: Flächenträgheitsmoment [unit: m^4] ).


I want to design an extruded aluminum profile for minimum weight and maximum bending stiffness.
The cross section will be far away from a combination of simple shapes, so I cannot calculate it by hand.
But I want to use the tool from _UR to compute Ixx.

My workflow becomes problematic towards the end:
Sketcher:
I design only one half of the cross section. I will try to attach this file.
Draft:
I use Draft2Sketch to get a DWire from the sketch.
Then I mirror the DWire at the x-axis (horizontally).
Then I use the upgrade tool to get one whole DWire (upper half and its mirrored lower half). But this does not work for me. I guess I do something wrong in the way I select parts during the upgrade procedure.

My goal: Have the whole profile cross section as DWire and use the script from UR_ to compute Ixx.

For the very simple profile (only its upper half is sketched) the result calculated by hand is Ixx=266cm^4.

Can somebody tell me what I am doing wrong?

OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.13340 (Git)
Build type: Release
Branch: master
Hash: 29864ff82173e501e220e754ccfe845b53990908
Python version: 2.7.14
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.1.0
Locale: German/Germany (de_DE)
Attachments
Profil_200x10.FCStd
(7.57 KiB) Downloaded 7 times