Skip to content

Commit b4e4dc9

Browse files
committed
get weaver to match
1 parent f1753d9 commit b4e4dc9

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

examples/weaver_1.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from pystran import section
1616
from pystran import plots
1717
from pystran import beam
18+
from pystran import rotation
1819

1920
# US customary units, inches, pounds, seconds
2021
L = 120.0
@@ -39,18 +40,22 @@
3940
model.add_support(m["joints"][3], model.CLAMPED)
4041
model.add_support(m["joints"][4], model.CLAMPED)
4142

42-
xz_vector = [1, 0, 0]
43+
xz_vector = [0, 0, 1]
4344
sect_1 = section.beam_3d_section(
4445
"sect_1", E=E, G=G, A=A, Ix=Ix, Iy=Iy, Iz=Iz, J=J, xz_vector=xz_vector
4546
)
46-
xz_vector = [0, 1, 0]
47+
xz_vector = [0, 0, 1]
4748
sect_2 = section.beam_3d_section(
4849
"sect_2", E=E, G=G, A=A, Ix=Ix, Iy=Iy, Iz=Iz, J=J, xz_vector=xz_vector
4950
)
51+
xz_vector = rotation.rotate(m["joints"][2], m["joints"][4], [0, 1, 0], 90)
52+
sect_3 = section.beam_3d_section(
53+
"sect_3", E=E, G=G, A=A, Ix=Ix, Iy=Iy, Iz=Iz, J=J, xz_vector=xz_vector
54+
)
5055

51-
model.add_beam_member(m, 1, [1, 2], sect_2)
52-
model.add_beam_member(m, 2, [3, 1], sect_1)
53-
model.add_beam_member(m, 3, [2, 4], sect_2)
56+
model.add_beam_member(m, 1, [1, 2], sect_1)
57+
model.add_beam_member(m, 2, [3, 1], sect_2)
58+
model.add_beam_member(m, 3, [2, 4], sect_3)
5459

5560
model.add_load(m["joints"][1], model.U1, F)
5661
model.add_load(m["joints"][2], model.U2, -P)

pystran/rotation.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from math import pi, cos, sin
77
import numpy
8+
from pystran.geometry import delt, len
89

910

1011
def rotmat3(rotvec):
@@ -34,3 +35,14 @@ def rotmat3(rotvec):
3435
R[1, 1] += ca
3536
R[2, 2] += ca
3637
return R
38+
39+
40+
def rotate(i, j, v, angleindegrees):
41+
"""
42+
Rotate a 3D vector `v` by an angle about the unit vector defined by joints `i`
43+
and `j`.
44+
"""
45+
ci, cj = i["coordinates"], j["coordinates"]
46+
uv = delt(ci, cj) / len(ci, cj)
47+
angle = angleindegrees * pi / 180.0
48+
return rotmat3(uv * angle).dot(numpy.array(v))

0 commit comments

Comments
 (0)