-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02 Profiles + Operations.dib
132 lines (85 loc) · 3.71 KB
/
02 Profiles + Operations.dib
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!meta
{"kernelInfo":{"defaultKernelName":"csharp","items":[{"aliases":[],"name":"csharp"}]}}
#!markdown
### Setup
#!csharp
#r "nuget: Hypar.Elements, *-*"
#!markdown
# Profiles and Solid Operations
#!markdown
## Profiles
Profiles are basically "Polygons with holes" — and they're a major geometry workhorse on Hypar. They're used to represent everything from the outlines of spaces, to building footprints, to the cross-sections of structural members.
#!csharp
var outerBoundary = Polygon.Rectangle((0,0), (10, 10));
var hole = Polygon.Rectangle((4,4), (8, 8));
var profile = new Profile(outerBoundary, hole);
return profile;
#!markdown
Profiles can have multiple holes, too:
#!csharp
var outerBoundary = Polygon.Rectangle((0,0), (10, 10));
var hole1 = Polygon.Rectangle((2,2), (4, 4));
var hole2 = Polygon.Rectangle((6,6), (8, 8));
var profile = new Profile(outerBoundary, new List<Polygon> { hole1, hole2 });
return profile;
#!markdown
## Solid Operations
We can also create solid geometry, not just curves. The two most common are the `Lamina`, which is basically a flat surface, and the `Extrude`, which is a straight extrusion along a vector. Both can be created from `Profile`s.
#!csharp
var lamina = new Lamina(profile);
return lamina;
#!csharp
var extrude = new Extrude(profile, 2, Vector3.ZAxis);
return extrude;
#!markdown
`Sweep`s are also supported:
#!csharp
using Elements.Geometry.Profiles;
var rail = new Polyline((0,0), (10,0), (10, 3), (12, 4));
var crossSection = new WideFlangeProfileFactory().GetProfileByType(WideFlangeProfileType.W24x94);
var sweep = new Sweep(crossSection, rail, 0, 0, 0, false);
return sweep;
#!markdown
## Representations
You can create a `Representation` out of multiple solid operations, for more complex geometry. Solid operations may be solid and void, so a representation can be a complex boolean:
#!csharp
var baseExtrude = new Extrude(Polygon.Ngon(6, 5), 6, new Vector3(0,0,1));
var void1 = new Extrude(Polygon.Ngon(4, 2), 7, Vector3.ZAxis, true);
var void2 = new Sweep(Polygon.Star(3, 2, 5), new Line((-5,0,3), (5, 0, 3)),0,0,0, true);
var representation = new Representation(new List<SolidOperation> { baseExtrude, void1, void2 });
return representation;
#!markdown
# Profile Operations
You can also perform useful 2D operations on profiles to create new Profiles. These include:
- `Profile.Offset`
- `Profile.Intersection`
- `Profile.UnionAll`
- `Profile.Split`
among others.
#!csharp
// Offset
var baseProfile = new Profile(Polygon.Star(10,6, 5));
var offsets = Profile.Offset(new [] {baseProfile}, 5);
return new List<Profile> { baseProfile }.Concat(offsets);
#!csharp
// Intersect
var p1 = new Profile(Polygon.Star(8,3, 5));
var p2 = new Profile(Polygon.Rectangle(2, 10));
var intersection = Profile.Intersection(new[] {p1}, new[] {p2});
// Use model curves to display with different colors
var curves = new List<ModelCurve>();
curves.AddRange(p1.ToModelCurves(null, BuiltInMaterials.XAxis));
curves.AddRange(p2.ToModelCurves(null, BuiltInMaterials.YAxis));
curves.AddRange(intersection.SelectMany((p) => p.ToModelCurves(null, BuiltInMaterials.ZAxis)));
return curves;
#!csharp
return Profile.UnionAll(new [] {p1, p2});
#!csharp
var splitLine1 = new Polyline((-10, 0), (0, 1), (10, 0));
var splitLine2 = new Polyline((0,-10), (3, 10));
var splits = Profile.Split(new [] {p1}, new Polyline[] {splitLine1, splitLine2});
var random = new Random(3);
return splits.Select(s => new Extrude(s, random.NextDouble() * 10, Vector3.ZAxis));
#!markdown
# Exercise
Create a profile with a hole, and create an extrude from it. Then, create a representation from the extrude. Consider adding an additional void operation to the represenation to subtract from the extrude. Finally, return the representation.