.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/continuum_mechanics/rotation.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_continuum_mechanics_rotation.py: Rotation library Examples ~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 5-13 .. code-block:: Python import numpy as np import matplotlib.pyplot as plt from scipy.spatial.transform import Rotation as R from simcoon import simmit as sim import os .. GENERATED FROM PYTHON SOURCE LINES 14-17 Rotation API examples These examples demonstrate the main rotation functions available in simcoon. .. GENERATED FROM PYTHON SOURCE LINES 17-26 .. code-block:: Python v = np.array([1.0, 0.0, 0.0]) m = np.eye(3) angle = np.pi / 4 # 45 degrees axis = 2 # y-axis (1=x, 2=y, 3=z) copy = True active = True .. GENERATED FROM PYTHON SOURCE LINES 27-31 1. Rotate a vector using a rotation matrix This example shows how to build a rotation matrix and rotate a vector. It uses :func:`simcoon.simmit.fillR_angle` and :func:`simcoon.simmit.rotate_vec_R`. .. GENERATED FROM PYTHON SOURCE LINES 31-39 .. code-block:: Python Rmat = sim.fillR_angle(angle, axis, active, copy) v_rot1 = sim.rotate_vec_R(v, Rmat, copy) print("Rotated vector (using R):", v_rot1) print("Rotation matrix (using R):", Rmat) .. rst-class:: sphx-glr-script-out .. code-block:: none Rotated vector (using R): [[ 0.70710678] [ 0. ] [-0.70710678]] Rotation matrix (using R): [[ 0.70710678 0. 0.70710678] [ 0. 1. 0. ] [-0.70710678 0. 0.70710678]] .. GENERATED FROM PYTHON SOURCE LINES 40-44 2. Rotate a vector using angle/axis This example shows how to rotate a vector using an angle and an axis directly. It uses :func:`simcoon.simmit.rotate_vec_angle`. .. GENERATED FROM PYTHON SOURCE LINES 44-50 .. code-block:: Python v_rot2 = sim.rotate_vec_angle(v, angle, axis, copy) print("Rotated vector (using angle/axis):", v_rot2) .. rst-class:: sphx-glr-script-out .. code-block:: none Rotated vector (using angle/axis): [[ 0.70710678] [ 0. ] [-0.70710678]] .. GENERATED FROM PYTHON SOURCE LINES 51-55 3. Rotate a matrix using a rotation matrix This example shows how to rotate a matrix using a rotation matrix. It uses :func:`simcoon.simmit.rotate_mat_R`. .. GENERATED FROM PYTHON SOURCE LINES 55-61 .. code-block:: Python m_rot1 = sim.rotate_mat_R(m, Rmat, copy) print("Rotated matrix (using R):\n", m_rot1) .. rst-class:: sphx-glr-script-out .. code-block:: none Rotated matrix (using R): [[1. 0. 0.] [0. 1. 0.] [0. 0. 1.]] .. GENERATED FROM PYTHON SOURCE LINES 62-66 4. Rotate a matrix using angle/axis This example shows how to rotate a matrix using an angle and an axis directly. It uses :func:`simcoon.simmit.rotate_mat_angle`. .. GENERATED FROM PYTHON SOURCE LINES 66-72 .. code-block:: Python m_rot2 = sim.rotate_mat_angle(m, angle, axis, copy) print("Rotated matrix (using angle/axis):\n", m_rot2) .. rst-class:: sphx-glr-script-out .. code-block:: none Rotated matrix (using angle/axis): [[1. 0. 0.] [0. 1. 0.] [0. 0. 1.]] .. GENERATED FROM PYTHON SOURCE LINES 73-77 5. Build a rotation matrix from Euler angles This example shows how to create a rotation matrix from Euler angles. It uses :func:`simcoon.simmit.fillR_euler`. .. GENERATED FROM PYTHON SOURCE LINES 77-83 .. code-block:: Python psi, theta, phi = np.pi / 6, np.pi / 4, np.pi / 3 R_euler = sim.fillR_euler(psi, theta, phi, active, "zxz", copy) print("Rotation matrix from Euler angles (zxz):\n", R_euler) .. rst-class:: sphx-glr-script-out .. code-block:: none Rotation matrix from Euler angles (zxz): [[ 0.12682648 -0.78033009 0.61237244] [ 0.9267767 -0.12682648 -0.35355339] [ 0.35355339 0.61237244 0.70710678]] .. GENERATED FROM PYTHON SOURCE LINES 84-88 Rotation of mechanical quantities These examples demonstrate how to rotate mechanical quantities such as stress, strain, and stiffness matrices. .. GENERATED FROM PYTHON SOURCE LINES 91-94 6. Rotate a stress vector (single and batch) This example uses :func:`simcoon.simmit.rotate_stress_angle`. .. GENERATED FROM PYTHON SOURCE LINES 94-103 .. code-block:: Python stress = np.array([1, 2, 3, 4, 5, 6], dtype=float) stress_batch = np.stack([stress, stress * 2], axis=1) rot_stress1 = sim.rotate_stress_angle(stress, angle, axis, active, copy) rot_stress2 = sim.rotate_stress_angle(stress_batch, angle, axis, active, copy) print("Rotated stress (single):", rot_stress1) print("Rotated stress (batch):\n", rot_stress2) .. rst-class:: sphx-glr-script-out .. code-block:: none Rotated stress (single): [[ 7. ] [ 2. ] [-3. ] [ 7.07106781] [ 1. ] [ 1.41421356]] Rotated stress (batch): [[ 7. 14. ] [ 2. 4. ] [-3. -6. ] [ 7.07106781 14.14213562] [ 1. 2. ] [ 1.41421356 2.82842712]] .. GENERATED FROM PYTHON SOURCE LINES 104-107 7. Rotate a strain vector (single and batch) This example uses :func:`simcoon.simmit.rotate_strain_angle`. .. GENERATED FROM PYTHON SOURCE LINES 107-116 .. code-block:: Python strain = np.array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6], dtype=float) strain_batch = np.stack([strain, strain * 2], axis=1) rot_strain1 = sim.rotate_strain_angle(strain, angle, axis, active, copy) rot_strain2 = sim.rotate_strain_angle(strain_batch, angle, axis, active, copy) print("Rotated strain (single):", rot_strain1) print("Rotated strain (batch):\n", rot_strain2) .. rst-class:: sphx-glr-script-out .. code-block:: none Rotated strain (single): [[ 0.45 ] [ 0.2 ] [-0.05 ] [ 0.70710678] [ 0.2 ] [ 0.14142136]] Rotated strain (batch): [[ 0.45 0.9 ] [ 0.2 0.4 ] [-0.05 -0.1 ] [ 0.70710678 1.41421356] [ 0.2 0.4 ] [ 0.14142136 0.28284271]] .. GENERATED FROM PYTHON SOURCE LINES 117-121 8. Rotate a stiffness matrix (L) This example uses both :func:`simcoon.simmit.rotateL_angle` and :func:`simcoon.simmit.rotateL_R`. .. GENERATED FROM PYTHON SOURCE LINES 121-129 .. code-block:: Python L6 = np.eye(6) rotL1 = sim.rotateL_angle(L6, angle, axis, active, copy) rotL2 = sim.rotateL_R(L6, Rmat, active, copy) print("Rotated L (angle):\n", rotL1) print("Rotated L (R):\n", rotL2) .. rst-class:: sphx-glr-script-out .. code-block:: none Rotated L (angle): [[ 1.50000000e+00 0.00000000e+00 -5.00000000e-01 0.00000000e+00 1.11022302e-16 0.00000000e+00] [ 0.00000000e+00 1.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00] [-5.00000000e-01 0.00000000e+00 1.50000000e+00 0.00000000e+00 -1.11022302e-16 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 1.00000000e+00 0.00000000e+00 -1.01465364e-17] [ 1.11022302e-16 0.00000000e+00 -1.11022302e-16 0.00000000e+00 5.00000000e-01 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 -1.01465364e-17 0.00000000e+00 1.00000000e+00]] Rotated L (R): [[ 1.50000000e+00 0.00000000e+00 -5.00000000e-01 0.00000000e+00 1.11022302e-16 0.00000000e+00] [ 0.00000000e+00 1.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00] [-5.00000000e-01 0.00000000e+00 1.50000000e+00 0.00000000e+00 -1.11022302e-16 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 1.00000000e+00 0.00000000e+00 -1.01465364e-17] [ 1.11022302e-16 0.00000000e+00 -1.11022302e-16 0.00000000e+00 5.00000000e-01 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 -1.01465364e-17 0.00000000e+00 1.00000000e+00]] .. GENERATED FROM PYTHON SOURCE LINES 130-134 9. Rotate a compliance matrix (M) This example uses both :func:`simcoon.simmit.rotateM_angle` and :func:`simcoon.simmit.rotateM_R`. .. GENERATED FROM PYTHON SOURCE LINES 134-142 .. code-block:: Python M6 = np.eye(6) rotM1 = sim.rotateM_angle(M6, angle, axis, active, copy) rotM2 = sim.rotateM_R(M6, Rmat, active, copy) print("Rotated M (angle):\n", rotM1) print("Rotated M (R):\n", rotM2) .. rst-class:: sphx-glr-script-out .. code-block:: none Rotated M (angle): [[ 7.50000000e-01 0.00000000e+00 2.50000000e-01 0.00000000e+00 -1.11022302e-16 0.00000000e+00] [ 0.00000000e+00 1.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 2.50000000e-01 0.00000000e+00 7.50000000e-01 0.00000000e+00 1.11022302e-16 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 1.00000000e+00 0.00000000e+00 -1.01465364e-17] [-1.11022302e-16 0.00000000e+00 1.11022302e-16 0.00000000e+00 2.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 -1.01465364e-17 0.00000000e+00 1.00000000e+00]] Rotated M (R): [[ 7.50000000e-01 0.00000000e+00 2.50000000e-01 0.00000000e+00 -1.11022302e-16 0.00000000e+00] [ 0.00000000e+00 1.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 2.50000000e-01 0.00000000e+00 7.50000000e-01 0.00000000e+00 1.11022302e-16 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 1.00000000e+00 0.00000000e+00 -1.01465364e-17] [-1.11022302e-16 0.00000000e+00 1.11022302e-16 0.00000000e+00 2.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 -1.01465364e-17 0.00000000e+00 1.00000000e+00]] .. GENERATED FROM PYTHON SOURCE LINES 143-147 10. Rotate a strain concentration matrix (A) This example uses both :func:`simcoon.simmit.rotateA_angle` and :func:`simcoon.simmit.rotateA_R`. .. GENERATED FROM PYTHON SOURCE LINES 147-155 .. code-block:: Python A6 = np.eye(6) rotA1 = sim.rotateA_angle(A6, angle, axis, active, copy) rotA2 = sim.rotateA_R(A6, Rmat, active, copy) print("Rotated A (angle):\n", rotA1) print("Rotated A (R):\n", rotA2) .. rst-class:: sphx-glr-script-out .. code-block:: none Rotated A (angle): [[ 1.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 1.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 1.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 1.00000000e+00 0.00000000e+00 -1.01465364e-17] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 1.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 -1.01465364e-17 0.00000000e+00 1.00000000e+00]] Rotated A (R): [[ 1.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 1.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 1.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 1.00000000e+00 0.00000000e+00 -1.01465364e-17] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 1.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 -1.01465364e-17 0.00000000e+00 1.00000000e+00]] .. GENERATED FROM PYTHON SOURCE LINES 156-160 11. Rotate a stress concentration matrix (B) This example uses both :func:`simcoon.simmit.rotateB_angle` and :func:`simcoon.simmit.rotateB_R`. .. GENERATED FROM PYTHON SOURCE LINES 160-168 .. code-block:: Python B6 = np.eye(6) rotB1 = sim.rotateB_angle(B6, angle, axis, active, copy) rotB2 = sim.rotateB_R(B6, Rmat, active, copy) print("Rotated B (angle):\n", rotB1) print("Rotated B (R):\n", rotB2) .. rst-class:: sphx-glr-script-out .. code-block:: none Rotated B (angle): [[ 1.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 1.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 1.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 1.00000000e+00 0.00000000e+00 -1.01465364e-17] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 1.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 -1.01465364e-17 0.00000000e+00 1.00000000e+00]] Rotated B (R): [[ 1.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 1.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 1.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 1.00000000e+00 0.00000000e+00 -1.01465364e-17] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 1.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 -1.01465364e-17 0.00000000e+00 1.00000000e+00]] .. GENERATED FROM PYTHON SOURCE LINES 169-172 12. Rotate a cubic stiffness tensor Provide the elastic stiffness tensor for a cubic material and rotate it. .. GENERATED FROM PYTHON SOURCE LINES 172-198 .. code-block:: Python E = 70000.0 nu = 0.3 G = 23000.0 L = sim.L_cubic([E, nu, G], "EnuG") print(np.array_str(L, precision=2, suppress_small=True)) d = sim.check_symetries(L, 1.0e-2) print(d["umat_type"]) print(d["props"]) x = sim.L_cubic_props(L) print(x) alpha = np.pi / 4.0 rot_matrix = np.array( [[np.cos(alpha), -np.sin(alpha), 0.0], [np.sin(alpha), np.cos(alpha), 0], [0, 0, 1]] ) # print(R) L_rotate = sim.rotateL_R(L, rot_matrix) L_rotate_angle = sim.rotateL_angle(L, alpha, axis=3) print(np.array_str(L_rotate, suppress_small=True)) print(np.array_str(L_rotate_angle, suppress_small=True)) .. rst-class:: sphx-glr-script-out .. code-block:: none [[94230.77 40384.62 40384.62 0. 0. 0. ] [40384.62 94230.77 40384.62 0. 0. 0. ] [40384.62 40384.62 94230.77 0. 0. 0. ] [ 0. 0. 0. 23000. 0. 0. ] [ 0. 0. 0. 0. 23000. 0. ] [ 0. 0. 0. 0. 0. 23000. ]] ELCUB [[7.0e+04] [3.0e-01] [2.3e+04]] [[7.0e+04] [3.0e-01] [2.3e+04]] [[90307.69230769 44307.69230769 40384.61538462 0. 0. 0. ] [44307.69230769 90307.69230769 40384.61538462 -0. 0. 0. ] [40384.61538462 40384.61538462 94230.76923077 0. 0. 0. ] [ 0. 0. 0. 26923.07692308 0. 0. ] [ 0. 0. 0. 0. 23000. 0. ] [ 0. 0. 0. 0. -0. 23000. ]] [[90307.69230769 44307.69230769 40384.61538462 0. 0. 0. ] [44307.69230769 90307.69230769 40384.61538462 -0. 0. 0. ] [40384.61538462 40384.61538462 94230.76923077 0. 0. 0. ] [ 0. 0. 0. 26923.07692308 0. 0. ] [ 0. 0. 0. 0. 23000. 0. ] [ 0. 0. 0. 0. -0. 23000. ]] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.174 seconds) .. _sphx_glr_download_examples_continuum_mechanics_rotation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: rotation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: rotation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: rotation.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_