-
Notifications
You must be signed in to change notification settings - Fork 106
/
surfaceIntersection.html
143 lines (104 loc) · 3.78 KB
/
surfaceIntersection.html
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
133
134
135
136
137
138
139
140
141
142
143
<!DOCTYPE html>
<html>
<head>
<title>Surface-Surface Intersection</title>
<script src="js/verb.min.js"></script>
<script src="js/three.min.js"></script>
<script src="js/verbToThreeConversion.js"></script>
<script src="js/OrbitControls.js"></script>
<script src="js/codemirror.js"></script>
<script src="js/javascript.js"></script>
<script src="js/threeBasic.js"></script>
<link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,300' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/codemirror.css">
<link rel="stylesheet" href="css/example.css">
<link rel="stylesheet" href="css/colorforth.css">
</head>
<body>
<div id="button">Show/Hide Code</div>
<div id="viewer" class="col">
<div id="title"></div>
</div>
<div id="code-container" class="col scroll-y"></div>
</body>
<script id="script">
setupScene();
function exNurbsSurfacePlane(){
var degree = 3
, knots = [0, 0, 0, 0, 0.333, 0.666, 1, 1, 1, 1]
, pts = [ [ [0, 0, -10], [10, 0, 0], [20, 0, 0], [30, 0, 0] , [40, 0, 0], [50, 0, 9] ],
[ [0, -10, 0], [10, -10, 10], [20, -10, 10], [30, -10, 0] , [40, -10, 0], [50, -10, 0] ],
[ [0, -20, 0], [10, -20, 10], [20, -20, 10], [30, -20, 0] , [40, -20, -2], [50, -20, 0] ],
[ [0, -30, 0], [10, -30, 0], [20, -30, 0], [30, -30, 0] , [40, -30, 0], [50, -30, 0] ],
[ [0, -40, 0], [10, -40, 0], [20, -40, 0], [30, -40, 4] , [40, -40, -20], [50, -40, 0] ],
[ [0, -50, 12], [10, -50, 0], [20, -50, 0], [30, -50, 0] , [50, -50, 0], [50, -50, 15] ], ];
srf1 = new verb.geom.NurbsSurface.byKnotsControlPointsWeights( degree, degree, knots, knots, pts );
var p5 = [50,-50,3]
, p6 = [50,0,3]
, p7 = [0,0,3]
, p8 = [0,-50,5];
srf2 = verb.geom.NurbsSurface.byCorners( p5, p6, p7, p8 );
}
function exPlaneCylindricalSurface(){
var axis = [0,0,1]
, xaxis = [1,0,0]
, base = [0,0,0]
, height = 50
, radius = 30;
srf1 = new verb.geom.CylindricalSurface( axis, xaxis, base, height, radius );
var p5 = [50,50,50]
, p6 = [-50,50,50]
, p7 = [-50,-50,0]
, p8 = [50,-50,0];
srf2 = verb.geom.NurbsSurface.byCorners( p5, p6, p7, p8 );
}
function exTorusCylindricalSurface(){
// center, xaxis, yaxis, radius
var profile = new verb.geom.Circle( [5,0,0], [1,0,0], [0,0,1], 2 );
var base = [0,0,0];
var axis = [0,0,1];
var angle = 2 * Math.PI
srf1 = new verb.geom.RevolvedSurface( profile, base, axis, angle );
var axis = [-1,0,0]
, xaxis = [0,0,1]
, base = [8,0,0]
, height = 16
, radius = 2;
srf2 = new verb.geom.CylindricalSurface( axis, xaxis, base, height, radius );
}
function exTorusCylindricalSurface2(){
// center, xaxis, yaxis, radius
var profile = new verb.geom.Circle( [5,0,0], [1,0,0], [0,0,1], 2 );
var base = [0,0,0];
var axis = [0,0,1];
var angle = 2 * Math.PI
srf1 = new verb.geom.RevolvedSurface( profile, base, axis, angle );
var axis = [-1,0,0]
, xaxis = [0,0,1]
, base = [8,0,1]
, height = 16
, radius = 2;
srf2 = new verb.geom.CylindricalSurface( axis, xaxis, base, height, radius );
}
exNurbsSurfacePlane();
//exPlaneCylindricalSurface();
//exTorusCylindricalSurface();
//exTorusCylindricalSurface2();
addMeshToScene( srf1.toThreeGeometry() );
addMeshToScene( srf2.toThreeGeometry() );
var res;
var runs = 10;
var d1 = Date.now();
for (var i = 0 ; i < runs; i++){
res = verb.geom.Intersect.surfaces( srf1, srf2, 1e-6 );
}
var d2 = Date.now();
console.log( "intersected in ", (d2 - d1) / runs, " ms and " + res.length + " curves were discovered");
for (var i = 0; i < res.length; i++){
var res2 = res[i].toThreeGeometry();
addCurveToScene( res2 );
}
renderScene();
</script>
<script src="js/example.js"></script>
</html>