{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#  Examples 4 -- Moments\n",
    "\n",
    "Contents:\n",
    "- [A. Maximize the moment](#A)\n",
    "- [B. Net moment](#B)\n",
    "- [C. Net moment 2](#C)\n",
    "- [D. Moment about a line](#D)             \n",
    "- [E. Moment about a line 2](#E)             \n",
    "- [F. Force couple](#F)               \n",
    "- [G. Force couple 2](#G)                           \n",
    "- [H. Equivalent force system](#H)                           \n",
    "- [I. Equivalent force system 2](#I)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from numpy import *\n",
    "dtr = pi/180  # degree-to-radian conversion"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"A\"></a>\n",
    "\n",
    "## A. Maximize the moment\n",
    "\n",
    "<img src=\"images/P4-13.png\" />"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "R,X,Y = 0.5, 3.0, 4.0   # m\n",
    "limit = 24.0            # kN.m"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "First note that, in equilibrium, $\\left |\\vec{T}  \\right | = T = W$. \n",
    "\n",
    "\n",
    "For a given $T$, the maximum moment would be at the greatest perpendiculat distance from A to the line of action of force $\\vec{T}$. Therefore the greatest momemt arm is the distance from A through C (at the pulley center), to the opposite side of the pulley. A little geometry will show that $\\alpha$ is equal to the angle that $\\vec{r}_{AC}$ makes with the $-x$ axis, so\n",
    "\n",
    "$$\\tan \\alpha = \\frac{|\\vec{r}_{ACy}|}{|\\vec{r}_{ACx}|}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "rAC = array((-X,Y,0))\n",
    "alpha = arctan(abs(rAC[1]/rAC[0]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"images/P4-13a.png\" width=\"300\" height=\"300\" style=\"float:right\" align=\"right\" />\n",
    "\n",
    "Since $\\vec{T}$ (at maximum moment) will be perpendicular to $\\hat{u}_{AC}$, we can use the moment arms shown in the figure.\n",
    "\n",
    "So the total moment about A is\n",
    "\n",
    "$$M_A = W L_1 + W L_2$$\n",
    "\n",
    "where $L_1=X-R$ and $L_2=\\sqrt{X^2+Y^2}+R$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "angle of max moment is alpha= 53.13010235415598 deg\n",
      "maximum weight is W= 3.0 kN\n"
     ]
    }
   ],
   "source": [
    "L1 = X-R\n",
    "L2 = sqrt(X**2+Y**2) + R\n",
    "W = limit / (L1+L2)\n",
    "print ('angle of max moment is alpha=',alpha/dtr,'deg')\n",
    "print ('maximum weight is W=',W,'kN')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"B\"></a>\n",
    "\n",
    "## B. Net moment\n",
    "\n",
    "<img src=\"images/P4-21.png\" />"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "FA  = array(( 34000., 0, 0    ))   # lb\n",
    "FB  = array(( 29870., 0, 4400 ))   # lb\n",
    "rOA = array((   8., 27., -8  ))    # ft\n",
    "rOB = array(( -85.,   0, 21  ))    # ft"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[      0.  729270. -918000.]\n"
     ]
    }
   ],
   "source": [
    "MO = cross(rOA,FA) + cross(rOB,FB)\n",
    "print (MO)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"C\"></a>\n",
    "\n",
    "## C. Net moment 2\n",
    "\n",
    "<img src=\"images/P4-22.png\" />"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "x1,x2 = 10., 13.     # in;  OAx, ODx\n",
    "y = 13.              # in\n",
    "z1,z2 = 15., 18.     # in;  OBz, BCz\n",
    "T_mag = 68.          # lb\n",
    "P_mag = 105.         # lb\n",
    "F_mag = 220.         # lb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "answer:\n",
      "   MB= [ 3528.20770825   332.14791673 -2860.        ] in.lb\n",
      "   MO= [ 8043.38079847   608.93784733 -2860.        ] in.lb\n"
     ]
    }
   ],
   "source": [
    "# define position and force vectors\n",
    "rOA = array(( x1, y,   0   ))\n",
    "rOB = array((  0, 0, z1    ))\n",
    "rOC = array((  0, 0, z1+z2 ))\n",
    "rOD = array(( x2, 0, z1+z2 ))\n",
    "F = F_mag*array((0,-1,0))\n",
    "P = P_mag*array((0,-1,0))\n",
    "rCA = rOA - rOC\n",
    "uCA = rCA / sqrt(sum(rCA**2))\n",
    "T = T_mag*uCA\n",
    "# perform cross products\n",
    "rBC = rOC - rOB\n",
    "rBD = rOD - rOB\n",
    "MB = cross(rBC,T) + cross(rBD,F)\n",
    "MO = cross(rOC,T) + cross(rOD,F) + cross(rOB,P)\n",
    "print ('answer:')\n",
    "print ('   MB=',MB,'in.lb')\n",
    "print ('   MO=',MO,'in.lb')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"D\"></a>\n",
    "\n",
    "## D. Moment about a line\n",
    "\n",
    "<img src=\"images/P4-35.png\" />\n",
    "\n",
    "A rectangular piece of sheet metal is clamped along edge *AB* in a machine called a *brake*. The sheet is to be bent along line *AB* by applying a *y*-direction force *F*. Determine the moment about line *AB* if *F* = 245 lb."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "x1,x2 = 24., 11.  # in;  left-to-right\n",
    "z = 12.           # in\n",
    "F_mag = 205.      # lb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "moment about line AB= -3208.757547712198 in.lb\n"
     ]
    }
   ],
   "source": [
    "# define vectors\n",
    "rOA = array((     0, 0, z ))\n",
    "rOB = array((    x1, 0, 0 ))\n",
    "rOC = array(( x1+x2, 0, z ))\n",
    "F = F_mag*array((0,1,0))\n",
    "# do the work (vector method)\n",
    "rBC = rOC - rOB\n",
    "MB = cross(rBC,F)\n",
    "rAB = rOB - rOA\n",
    "uAB = rAB / sqrt(sum(rAB**2))\n",
    "M_AB = dot(MB,uAB)\n",
    "print ('moment about line AB=',M_AB,'in.lb')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"E\"></a>\n",
    "\n",
    "## E. Moment about a line 2\n",
    "\n",
    "<img src=\"images/P4-39.png\" />"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "X = 8.   # in\n",
    "Y = 2.   # in\n",
    "AB_lim = 6.3  # in.lb\n",
    "BC_lim = 5.0  # in.lb"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Compute the moment of the force about point B:\n",
    "\n",
    "$$\\vec{M}_B = \\vec{r}_{BD} \\times \\vec{F} =  Y \\hat{\\jmath} \\times (-F \\hat{k}) = -YF \\hat{\\imath} $$\n",
    "\n",
    "Then dot this with the two unit vectors $\\hat{u}_{BA}$ and  $\\hat{u}_{BC}$. \n",
    "\n",
    "$$M_{BA} = -YF$$\n",
    "\n",
    "and\n",
    "\n",
    "$$M_{BC} =  -YF \\hat{\\imath} \\cdot \\hat{u}_{BC} = \\frac{-XYF}{\\sqrt{X^2+Y^2}} $$\n",
    "\n",
    "Set the moment about the line to the given limit and compute what force is required in each case."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "force limit for AB is 3.15 lb\n",
      "force limit for BC is 2.576941016011038 lb\n"
     ]
    }
   ],
   "source": [
    "rBD = array(( 0., Y, 0.))\n",
    "rBC = array((  X, Y, 0.))\n",
    "uBA = array(( 1., 0, 0.))\n",
    "uBC = rBC/sqrt(sum(rBC**2))\n",
    "# force limits for each moment:\n",
    "F_AB = AB_lim / Y\n",
    "F_BC = BC_lim * sqrt(X**2+Y**2) / (X*Y)\n",
    "print ('force limit for AB is',F_AB,'lb')\n",
    "print ('force limit for BC is',F_BC,'lb')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The lesser of these is the answer."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"F\"></a>\n",
    "\n",
    "## F. Force couple\n",
    "\n",
    "<img src=\"images/P4-67.png\" />"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "f = 0.3  # fraction of normal force contributing to applied force\n",
    "NA = 7.  # N\n",
    "r = 23.  # mm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "FA= 2.1 N\n",
      "FB= 2.1 N\n",
      "NB= 7.0 N\n",
      "M= -96.60000000000001 N.mm in the x-direction\n"
     ]
    }
   ],
   "source": [
    "FA = f*NA\n",
    "FB = FA\n",
    "NB = NA\n",
    "M = -2*r*FA\n",
    "print ('FA=',FA,'N')\n",
    "print ('FB=',FB,'N')\n",
    "print ('NB=',NB,'N')\n",
    "print ('M=',M,'N.mm in the x-direction')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Careful about the sign of the $\\hat{\\imath}$ component of $\\vec{M}$."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"G\"></a>\n",
    "\n",
    "## G. Force couple 2\n",
    "\n",
    "<img src=\"images/P4-76.png\" />"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "F1,F2 = 200.,265.       # N; upper, lower\n",
    "y1,y2,y3 = 1.0,2.0,4.5  # m; bottom, mid, top"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total moment M= [ 265.    0. -500.] N.m\n"
     ]
    }
   ],
   "source": [
    "M1 = F1*(y3-y2)*array((0.,0,-1))\n",
    "M2 = F2*(y2-y1)*array((1.,0, 0))\n",
    "print ('total moment M=',M1+M2,'N.m')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"H\"></a>\n",
    "\n",
    "## H. Equivalent force system\n",
    "\n",
    "<img src=\"images/P4-98.png\" />"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "radius = 60e-3  # m\n",
    "FA_mag = 555.   # N\n",
    "FB_mag = 636.   # N\n",
    "FC_mag = 724.   # N\n",
    "QB = 30*dtr     # radians\n",
    "QC = 30*dtr     # radians"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0.  33.3  0. ]\n",
      "[-33.04752941 -19.08         0.        ]\n",
      "[ 37.62014354 -21.72         0.        ]\n",
      "check moment: [ 4.57261413 -7.5         0.        ]\n",
      "(a)\n",
      "    FRz= -1915.0 N\n",
      "    MO=( 4.572614131981837 i + -7.4999999999999964 j)N.m\n",
      "(b)\n",
      "    FRz= -1915.0 N\n",
      "    x= -3.9164490861618786 mm\n",
      "    y= -2.387788058476155 mm\n"
     ]
    }
   ],
   "source": [
    "# part a\n",
    "khat = array((0.,0.,1.))\n",
    "FA = -FA_mag*khat\n",
    "FB = -FB_mag*khat\n",
    "FC = -FC_mag*khat\n",
    "FR = FA + FB + FC\n",
    "rOA = radius*array((1.,0,0))\n",
    "rOB = radius*array((-sin(QB), cos(QB), 0))\n",
    "rOC = radius*array((-sin(QC),-cos(QC), 0))\n",
    "MO = cross(rOA,FA) + cross(rOB,FB) + cross(rOC,FC)\n",
    "print (cross(rOA,FA))\n",
    "print (cross(rOB,FB))\n",
    "print (cross(rOC,FC))\n",
    "# part b\n",
    "MO_mag = sqrt(sum(MO**2))\n",
    "uM = MO/MO_mag\n",
    "uM_perp = array((uM[1],-uM[0], 0))\n",
    "FR_mag = sqrt(sum(FR**2))\n",
    "r_mag = MO_mag/FR_mag\n",
    "r = r_mag*uM_perp\n",
    "print ('check moment:',cross(r,FR))\n",
    "# answers:\n",
    "print ('(a)')\n",
    "print ('    FRz=',FR[2],'N')\n",
    "print ('    MO=(',MO[0],'i +',MO[1],'j)N.m')\n",
    "print ('(b)')\n",
    "print ('    FRz=',FR[2],'N')\n",
    "print ('    x=',r[0]*1e3,'mm')\n",
    "print ('    y=',r[1]*1e3,'mm')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"I\"></a>\n",
    "\n",
    "## I. Equivalent force system 2\n",
    "\n",
    "<img src=\"images/P4-123.png\" />"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "F1 = 6.07      # kN\n",
    "F2 = 2.84      # kN\n",
    "F3 = 4.76      # kN\n",
    "x1,x2 = 2.76,1.14  # m  left,right"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(a)\n",
      "    FR= -13.67 kN\n",
      "    MR= -6.2177999999999995 kN.m\n",
      "(b)\n",
      "    FR= -13.67 kN\n",
      "    x= 4.354850036576444 m\n"
     ]
    }
   ],
   "source": [
    "# part a\n",
    "FR = -F1 - F2 - F3\n",
    "MR = F1*x2 - F3*x1\n",
    "# part b\n",
    "r = MR/FR\n",
    "x = x1+x2+r\n",
    "# answers\n",
    "print ('(a)')\n",
    "print ('    FR=',FR,'kN')\n",
    "print ('    MR=',MR,'kN.m')\n",
    "print ('(b)')\n",
    "print ('    FR=',FR,'kN')\n",
    "print ('    x=',x,'m')"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
