Help wanted. Python script for second moment of area
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
-
- Posts: 8
- Joined: Sun Sep 11, 2016 10:35 pm
Help wanted. Python script for second moment of area
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
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
Re: Help wanted. Python script for second moment of area
This is really not a big task.
Please see this quick'n'dirty example. It's for free
Macro:
File:
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)
Please see this quick'n'dirty example. It's for free
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
File:
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)
Re: Help wanted. Python script for second moment of area
hi UR_
same result with Macro_FCInfo
interesting your macro
i replace your two first line with (for use directly with object selected)
I can add these code lines to my macro ?
mario
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
Code: Select all
print "staticmoments ", Ix, " ", Iy, " ", Iz
print "Inertia about [0,0,0] ", Ixxtrans, " ", Iyytrans, " ", Izztrans
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
My macros on Gist.github here complete macros Wiki and forum.
-
- Posts: 8
- Joined: Sun Sep 11, 2016 10:35 pm
Re: Help wanted. Python script for second moment of area
UR_ and mario52
I thank you very much.
I thank you very much.
-
- Posts: 8
- Joined: Sun Sep 11, 2016 10:35 pm
Re: Help wanted. Python script for second moment of area
UR_
Hello.
How do you create DWire object from the Sketch in your file ?
Hello.
How do you create DWire object from the Sketch in your file ?
Re: Help wanted. Python script for second moment of area
In Draft workbench is a tool DraftToSketch which converts in both directions depending on the selected input.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
-
- Posts: 8
- Joined: Sun Sep 11, 2016 10:35 pm
Re: Help wanted. Python script for second moment of area
chrisb
Thanks a lot. It worked beautifully
Thanks a lot. It worked beautifully
Re: Help wanted. Python script for second moment of area
You're welcome. I use it usually in the other direction to convert from svg files to sketches.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
-
- Posts: 5
- Joined: Fri Mar 02, 2018 3:18 pm
- Location: Darmstadt/Germany
Re: Help wanted. Python script for second moment of area
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)
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 102 times
-
- Posts: 8
- Joined: Sun Sep 11, 2016 10:35 pm
Re: Help wanted. Python script for second moment of area
Hallo lukassturm
I did not see your message until today.
Tomorrow I will give you a look to your question.
Best regards
Auf Wiederhören.
Alejandro
I did not see your message until today.
Tomorrow I will give you a look to your question.
Best regards
Auf Wiederhören.
Alejandro