Mohr's Circle (TurboCAD Tutorial) - Ty Harness 11 June 2003


Introduction to Mohr's Circle

Mohr's Circle is a graphical aid to the solution of a compound stress problem. A combination of normal and shearing stresses at a point.



Mohr's circle is often studied in the first and second year of your degree and then in the final year it becomes embedded into your elasticity course. With the aid of Mohr's circle you can quickly calculate or formulate the principal stresses sigma1 and sigma2. The principal stresses and maximum Shear Stress (tau max) are used in all the common failure criterions. The Principal stresses are found when the element's viewpoint is rotated to indicate zero shear stress. The angles of sigma1 and sigma2 are the principal planes.



Plotting the normal stress against the shear stress it becomes very easy to calculate or formulate the principal stress and axes. One thing I haven't discussed is the units of stress: Pounds per square inch or Newtons per metre squared and so on - the key thing is sigma x, sigma y and tau xy must be the same units and the results will then be the same units.



It's a useful tool for mechanics and design engineers. Most basic mechanics books cover Mohr's Circle in a greater depth than above. Although some of the more mathematically biased ignore Mohr's circle in favour of a more general formulation of stress. The TurboCAD VBA App that follows plots out all the above diagrams.



The aim of this tutorial is to evaluate TurboCAD's VBA. The ability to add VBA routines makes a CAD Application even more powerful and productive. State-of-the-Art engineering software is so expensive and complicated to use that true understanding of your problem can be lost because the application is solving its problem and not yours. I think you learn a lot by simplifying and attempting to solve your own engineering problems.

As soon as I installed TurboCAD I went straight for the VBA and whether you're used to VBA in MS Excel, Word, AutoCAD etc they've all got there slight differences when it comes to the implementation, but VBA is one the easiest programming languages to learn and if you haven't used VBA before then I hope the code below will help get you started.

I haven't given you the compiled TCM file. Unfortunately there is no such thing as a source code file with VBA but you can just copy and paste the code below into the VBA editor.
TurboCAD House Keeping


Open up TC
Start a new drawing (say) from template and choose Normal Metric
Tools
VBA Macros
Macros


In the project scope textbox - type a new name (say) test1
New
Editor
Insert Module
Insert Userform
Dbl Click module 1 and enter the following code



Public Const PI = 3.14159

Sub mohrcircle()
UserForm1.Show
End Sub


Navigate to the Userform and Dbl click the Userform. Insert 3 labels, 3 textboxes, and 2 commandbuttons. See figure below



Press
View
Code
Copy and Paste the following code into the VBA editor


Private Sub CommandButton1_Click() ’I've found TC can crash if you use Unload Me Me.Hide ’In fact I'm abit wary to free any objects because I'm not 100% on the teardown ’process. I would have thought even if I had freed an object ’from the memory and then TC tried to do it then TC would exit gracefully????? End Sub
Private Function checkforblock(name As String) As Boolean ’see if the block already exist in the block collection Dim b As Block For Each b In ActiveDrawing.Blocks     If b.name = name Then     checkforblock = True     Exit Function     End If Next b checkforblock = False End Function
Private Sub MakeTestBlock() ’make a Standalone graphic Dim g As New Graphic g.Graphics.AddLineSingle -1, 0, 0, 1, 0, 0 g.Graphics.AddLineSingle 1, 0, 0, 1, 10, 0 g.Graphics.AddLineSingle 1, 10, 0, 3, 10, 0 g.Graphics.AddLineSingle 3, 10, 0, 0, 20, 0 g.Graphics.AddLineSingle 0, 20, 0, -3, 10, 0 g.Graphics.AddLineSingle -3, 10, 0, -1, 10, 0 g.Graphics.AddLineSingle -1, 10, 0, -1, 0, 0 ’This has to be inserted for some reason??? ActiveDrawing.Graphics.AddGraphic g Dim i As New Vertex ’the insertion vertex i.x = 0 i.Y = 0 i.Z = 0 ’turn the graphic into a block Dim b As Block Set b = ActiveDrawing.Blocks.Add("test", g) b.Anchor = i ’remove the unwanted graphic it from the drawing g.Delete End Sub
Private Sub CommandButton2_Click() ’This is the main code for calculating and drawing Mohr's Circle ’First check if my arrow block exits If checkforblock("test") = False Then MakeTestBlock ’FOrce into ModelSpace ForceModalSpace Dim rad As Double Dim x1 As Double Dim y1 As Double Dim x2 As Double Dim y2 As Double Dim dx As Double Dim dy As Double x1 = CDbl(TextBox1.Text) ’Sigmax y1 = CDbl(TextBox3.Text) ’tauxy x2 = CDbl(TextBox2.Text) ’Sigmay y2 = -1 * y1  ’Tauyx dx = (x2 - x1) dy = (y2 - y1) rad = Sqr(dx ^ 2 + dy ^ 2) * 0.5 Ang = Atn(dy / dx) ’< Sigma2 round to the greater of the normal stresses ActiveDrawing.Graphics.AddCross x1, y1, 0 ’sigmax,tauxy ActiveDrawing.Graphics.AddCross x2, y2, 0 ’sigmay,tauyx  top of intial element Dim l As Graphic Set l = ActiveDrawing.Graphics.AddLineSingle(x1, y1, 0, x2, y2, 0) l.Properties("PenColor").Value = RGB(255, 0, 0) Dim mpx As Double, mpy As Double mpx = x1 / 2 + x2 / 2 mpy = y1 / 2 + y2 / 2 Dim c As Graphic Set c = ActiveDrawing.Graphics.AddCircleCenterAndPoint(mpx, mpy, 0, x1, y1, 0) Dim Sigma1 As Double, sigma2 As Double, tau As Double Sigma1 = mpx - rad sigma2 = mpx + rad ’sigma2 is conventially the largest tau = rad ’Apply the text summary ActiveDrawing.Graphics.AddText "Compound Stress Mohr's Circle", -1.2 * rad, 2.6 * rad, 0, rad * 0.1 ActiveDrawing.Graphics.AddText "SigmaX = " & TextBox1.Text, -1.2 * rad, 2.2 * rad, 0, rad * 0.1 ActiveDrawing.Graphics.AddText "SigmaY = " & TextBox2.Text, -1.2 * rad, 2# * rad, 0, rad * 0.1 ActiveDrawing.Graphics.AddText "Tau = " & TextBox3.Text, -1.2 * rad, 1.8 * rad, 0, rad * 0.1 ActiveDrawing.Graphics.AddText "Sigma1 = " & CStr(Sigma1), -1.2 * rad, 1.6 * rad, 0, rad * 0.1 ActiveDrawing.Graphics.AddText "Sigma2 = " & CStr(sigma2), -1.2 * rad, 1.4 * rad, 0, rad * 0.1 ActiveDrawing.Graphics.AddText "Tau Max = " & CStr(tau), -1.2 * rad, 1.2 * rad, 0, rad * 0.1 ActiveDrawing.Graphics.AddText "Angle = " & CStr(Ang), -1.2 * rad, rad, 0, rad * 0.1 ActiveDrawing.Graphics.AddText "Ang1 = " & CStr(Ang * 0.5), -1.2 * rad, 0.8 * rad, 0, rad * 0.1 ’Draw in the Axes ActiveDrawing.Graphics.AddLineSingle Sigma1 - 1.2 * rad, 0, 0, sigma2 + 1.2 * rad, 0, 0 ActiveDrawing.Graphics.AddLineSingle 0, -1.2 * rad, 0, 0, 1.2 * rad, 0 ActiveDrawing.Graphics.AddText "0,0", 0.2, rad * 0.1, 0, rad * 0.1 ActiveDrawing.Graphics.AddText "Tensile stress", sigma2 + 0.1 * rad, rad * 0.1, 0, rad * 0.1 ActiveDrawing.Graphics.AddText "Compressive stress", -1.2 * rad, rad * 0.1, 0, rad * 0.1 ActiveDrawing.Graphics.AddText "Shear stress", -rad * 0.1, rad, 0, rad * 0.1, 1.5708 ’Draw the intial element DrawStessedElement -2 * rad - 2 * sigma2, 0, rad, 0, "Sigma y", "Sigma x", True ’Draw the prinipal axes If x1 > x2 Then DrawStessedElement 2 * rad + 2 * sigma2, 0, rad, Ang * 0.5, "Sigma 1", "Sigma 2", False Else DrawStessedElement 2 * rad + 2 * sigma2, 0, rad, Ang * 0.5, "Sigma 2", "Sigma 1", False End If   End Sub
Private Sub DrawStessedElement(cenx As Double, ceny As Double, size As Double, Ang As Double, Sigma1 As String, sigma2 As String, shearforces As Boolean) ’draw on the normal stresses and shearstresses ’I really should reverse arrow directions for compression a negative shear direction Dim x1 As Double, y1 As Double, x2 As Double, y2 As Double Dim r As Graphic x1 = -0.5 * size y1 = -0.5 * size x2 = 0.5 * size y2 = 0.5 * size ’put in the rectang element Set r = ActiveDrawing.Graphics.AddLineRectangle(x1, y1, 0, x2, y2, 0) r.MoveAbsolute cenx, ceny, 0 r.RotateAxis Ang ’draw the first arrow''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim a As Graphic Set a = ActiveDrawing.Graphics.AddBlockInsertion("test", 0, y2, 0, 0.2, 0.5, , 0) a.RotateAxis Ang, , , , 0, 0, 0 a.MoveRelative cenx, ceny, 0 ’apply sigma1 text Dim t As Graphic Set t = ActiveDrawing.Graphics.AddText(Sigma1, 0, y2 + 15, 0, size / 3, 0) t.RotateAxis Ang, , , , 0, 0, 0 t.MoveRelative cenx, ceny, 0 ’draw the second arrow''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Set a = ActiveDrawing.Graphics.AddBlockInsertion("test", 0, y1, 0, 0.2, 0.5, , PI) a.RotateAxis Ang, , , , 0, 0, 0 a.MoveRelative cenx, ceny, 0 Set t = ActiveDrawing.Graphics.AddText(Sigma1, 0, y1 - 15, 0, size / 3, 0) t.RotateAxis Ang, , , , 0, 0, 0 t.MoveRelative cenx, ceny, 0 ’draw the 3rd arrow''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Set a = ActiveDrawing.Graphics.AddBlockInsertion("test", x1, 0, 0, 0.2, 0.5, , 0.5 * PI) a.RotateAxis Ang, , , , 0, 0, 0 a.MoveRelative cenx, ceny, 0 Set t = ActiveDrawing.Graphics.AddText(sigma2, x1 - 15, 0, 0, size / 3, 0) t.RotateAxis Ang, , , , 0, 0, 0 t.MoveRelative cenx, ceny, 0 ’draw the fourth arrow''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Set a = ActiveDrawing.Graphics.AddBlockInsertion("test", x2, 0, 0, 0.2, 0.5, , -0.5 * PI) a.RotateAxis Ang, , , , 0, 0, 0 a.MoveRelative cenx, ceny, 0 Set t = ActiveDrawing.Graphics.AddText(sigma2, x2 + 15, 0, 0, size / 3, 0) t.RotateAxis Ang, , , , 0, 0, 0 t.MoveRelative cenx, ceny, 0 ’apply the shear arrows If shearforces = False Then Exit Sub ’Draw the shearforce Arrows Set a = ActiveDrawing.Graphics.AddBlockInsertion("test", x2 - 3, y2 + 0.5, 0, 0.05, 0.15, , -0.5 * PI) a.RotateAxis Ang, , , , 0, 0, 0 a.MoveRelative cenx, ceny, 0 Set a = ActiveDrawing.Graphics.AddBlockInsertion("test", y2 + 0.5, y2 - 3, 0, 0.05, 0.15, , 0) a.RotateAxis Ang, , , , 0, 0, 0 a.MoveRelative cenx, ceny, 0 Set a = ActiveDrawing.Graphics.AddBlockInsertion("test", x1 + 3, y1 - 0.5, 0, 0.05, 0.15, , 0.5 * PI) a.RotateAxis Ang, , , , 0, 0, 0 a.MoveRelative cenx, ceny, 0 Set a = ActiveDrawing.Graphics.AddBlockInsertion("test", y1 - 0.5, y1 + 3, 0, 0.05, 0.15, , PI) a.RotateAxis Ang, , , , 0, 0, 0 a.MoveRelative cenx, ceny, 0 Set t = ActiveDrawing.Graphics.AddText("Tau", x2 + size / 3, y2 + size / 3, 0, size / 3, 0) t.RotateAxis Ang, , , , 0, 0, 0 t.MoveRelative cenx, ceny, 0 Set t = ActiveDrawing.Graphics.AddText("Tau", x1 - size / 3, y1 - size / 3, 0, size / 3, 0) t.RotateAxis Ang, , , , 0, 0, 0 t.MoveRelative cenx, ceny, 0 End Sub
Private Sub DrawPrincipalElement(cenx As Double, ceny As Double, size As Double, Ang As Double) Dim x1 As Double, y1 As Double, x2 As Double, y2 As Double Dim r As Graphic x1 = -0.5 * size y1 = -0.5 * size x2 = 0.5 * size y2 = 0.5 * size Set r = ActiveDrawing.Graphics.AddLineRectangle(x1, y1, 0, x2, y2, 0) r.RotateAxis Ang r.MoveAbsolute cenx, ceny, 0 End Sub
Private Sub ForceModalSpace() Dim MSpace As Long MSpace = ActiveDrawing.Properties("TileMode")   If MSpace <> 1 Then     ActiveDrawing.Properties("TileMode").Value = 1   End If End Sub


File
Save the VBA in TurboCAD's macro path

You can then load this VBA App. into any drawing where you would need to calculate the normal stresses. Perhaps the design of a crankshaft etc.

I've used VB2HTML ( http://www.adit.co.uk ) to convert the VBA source into HTML.