-
-
Notifications
You must be signed in to change notification settings - Fork 35.7k
/
Copy pathParametricFunctions.js
100 lines (73 loc) · 2.87 KB
/
ParametricFunctions.js
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
/**
* @module ParametricFunctions
* @three_import import * as ParametricFunctions from 'three/addons/geometries/ParametricFunctions.js';
*/
/**
* A parametric function representing the Klein bottle.
*
* @param {number} v - The `v` coordinate on the surface in the range `[0,1]`.
* @param {number} u - The `u` coordinate on the surface in the range `[0,1]`.
* @param {Vector3} target - The target vector that is used to store the method's result.
*/
function klein( v, u, target ) {
u *= Math.PI;
v *= 2 * Math.PI;
u = u * 2;
let x, z;
if ( u < Math.PI ) {
x = 3 * Math.cos( u ) * ( 1 + Math.sin( u ) ) + ( 2 * ( 1 - Math.cos( u ) / 2 ) ) * Math.cos( u ) * Math.cos( v );
z = - 8 * Math.sin( u ) - 2 * ( 1 - Math.cos( u ) / 2 ) * Math.sin( u ) * Math.cos( v );
} else {
x = 3 * Math.cos( u ) * ( 1 + Math.sin( u ) ) + ( 2 * ( 1 - Math.cos( u ) / 2 ) ) * Math.cos( v + Math.PI );
z = - 8 * Math.sin( u );
}
const y = - 2 * ( 1 - Math.cos( u ) / 2 ) * Math.sin( v );
target.set( x, y, z );
}
/**
* A parametric function representing a flat plane.
*
* @param {number} u - The `u` coordinate on the surface in the range `[0,1]`.
* @param {number} v - The `v` coordinate on the surface in the range `[0,1]`.
* @param {Vector3} target - The target vector that is used to store the method's result.
*/
function plane( u, v, target ) {
target.set( u, 0, v );
}
/**
* A parametric function representing a flat mobius strip.
*
* @param {number} u - The `u` coordinate on the surface in the range `[0,1]`.
* @param {number} t - The `v` coordinate on the surface in the range `[0,1]`.
* @param {Vector3} target - The target vector that is used to store the method's result.
*/
function mobius( u, t, target ) {
// http://www.wolframalpha.com/input/?i=M%C3%B6bius+strip+parametric+equations&lk=1&a=ClashPrefs_*Surface.MoebiusStrip.SurfaceProperty.ParametricEquations-
u = u - 0.5;
const v = 2 * Math.PI * t;
const a = 2;
const x = Math.cos( v ) * ( a + u * Math.cos( v / 2 ) );
const y = Math.sin( v ) * ( a + u * Math.cos( v / 2 ) );
const z = u * Math.sin( v / 2 );
target.set( x, y, z );
}
/**
* A parametric function representing a volumetric mobius strip.
*
* @param {number} u - The `u` coordinate on the surface in the range `[0,1]`.
* @param {number} t - The `v` coordinate on the surface in the range `[0,1]`.
* @param {Vector3} target - The target vector that is used to store the method's result.
*/
function mobius3d( u, t, target ) {
u *= Math.PI;
t *= 2 * Math.PI;
u = u * 2;
const phi = u / 2;
const major = 2.25, a = 0.125, b = 0.65;
let x = a * Math.cos( t ) * Math.cos( phi ) - b * Math.sin( t ) * Math.sin( phi );
const z = a * Math.cos( t ) * Math.sin( phi ) + b * Math.sin( t ) * Math.cos( phi );
const y = ( major + x ) * Math.sin( u );
x = ( major + x ) * Math.cos( u );
target.set( x, y, z );
}
export { klein, plane, mobius, mobius3d };