-
Notifications
You must be signed in to change notification settings - Fork 3
/
TriaxialBraid.py
96 lines (77 loc) · 3.65 KB
/
TriaxialBraid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# =============================================================================
# TexGen: Geometric textile modeller.
# Copyright (C) 2006 Martin Sherburn
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# =============================================================================
from TexGen.Core import *
import math
# Create a textile
Textile = CTextile()
# Create a python list containing 3 yarns
Yarns = [CYarn(), CYarn(), CYarn()]
# Add nodes to the yarns to describe their paths
# First define the angled yarns
Yarns[0].AddNode(CNode(XYZ(0, 0, 0)))
Yarns[0].AddNode(CNode(XYZ(0.5, 0.2887, 0.2)))
Yarns[0].AddNode(CNode(XYZ(1, 0.5774, 0.2)))
Yarns[0].AddNode(CNode(XYZ(1.5, 0.8660, 0)))
Yarns[0].AddNode(CNode(XYZ(2, 1.1547, 0)))
Yarns[1].AddNode(CNode(XYZ(0, 0, 0.2)))
Yarns[1].AddNode(CNode(XYZ(0.5, -0.2887, 0)))
Yarns[1].AddNode(CNode(XYZ(1, -0.5774, 0)))
Yarns[1].AddNode(CNode(XYZ(1.5, -0.8660, 0.2)))
Yarns[1].AddNode(CNode(XYZ(2, -1.1547, 0.2)))
# Define a straight yarn
Yarns[2].AddNode(CNode(XYZ(-0.25, 0, 0.1)))
Yarns[2].AddNode(CNode(XYZ(-0.25, 0.57735, 0.1)))
# Create a lenticular section for the +- angled yarns
AngledSection = CSectionLenticular(0.45, 0.13)
# The section will be rotated at the appropriate points to avoid interference
# So create an interpolated yarn section
AngledYarnSection = CYarnSectionInterpPosition(True, True)
# This is the rotation angle defined
RotationAngle = math.radians(12)
# Add rotated sections at 1/8 and 5/8 of the way along the yarn
# at angles of +- RotationAngle
AngledYarnSection.AddSection(1.0/8.0, CSectionRotated(AngledSection, -RotationAngle))
AngledYarnSection.AddSection(5.0/8.0, CSectionRotated(AngledSection, RotationAngle))
# Add unrotated sections to the interpolation at intervals of 1/4
AngledYarnSection.AddSection(0.0/4.0, AngledSection)
AngledYarnSection.AddSection(1.0/4.0, AngledSection)
AngledYarnSection.AddSection(2.0/4.0, AngledSection)
AngledYarnSection.AddSection(3.0/4.0, AngledSection)
# Assign the rotating cross-section to the angled yarns
Yarns[0].AssignSection(AngledYarnSection)
Yarns[1].AssignSection(AngledYarnSection)
# Add repeats to those yarns
Yarns[0].AddRepeat(XYZ(2, 0, 0))
Yarns[1].AddRepeat(XYZ(2, 0, 0))
# Create a lenticular section for the straight yarns and assign it
StraightSection = CSectionLenticular(0.6, 0.15)
Yarns[2].AssignSection(CYarnSectionConstant(StraightSection))
# Add repeats for the straight yarn
Yarns[2].AddRepeat(XYZ(1, 0, 0))
# Loop over all the yarns in the list
for Yarn in Yarns:
# Set the interpolation function
Yarn.AssignInterpolation(CInterpolationCubic())
# Set the resolution of the surface mesh created
Yarn.SetResolution(20)
# Add common repeat vector to the yarn
Yarn.AddRepeat(XYZ(0, 0.57735, 0))
# Add the yarn to our textile
Textile.AddYarn(Yarn)
# Create a domain and assign it to the textile
Textile.AssignDomain(CDomainPlanes(XYZ(0+0.25, 0, -0.1), XYZ(1+0.25, 1, 0.3)))
# Add the textile
AddTextile("triaxialbraid", Textile)