forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLineCurve.js
50 lines (26 loc) · 785 Bytes
/
LineCurve.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
import { Curve } from '../core/Curve';
function LineCurve( v1, v2 ) {
Curve.call( this );
this.v1 = v1;
this.v2 = v2;
}
LineCurve.prototype = Object.create( Curve.prototype );
LineCurve.prototype.constructor = LineCurve;
LineCurve.prototype.isLineCurve = true;
LineCurve.prototype.getPoint = function ( t ) {
if ( t === 1 ) {
return this.v2.clone();
}
var point = this.v2.clone().sub( this.v1 );
point.multiplyScalar( t ).add( this.v1 );
return point;
};
// Line curve is linear, so we can overwrite default getPointAt
LineCurve.prototype.getPointAt = function ( u ) {
return this.getPoint( u );
};
LineCurve.prototype.getTangent = function ( t ) {
var tangent = this.v2.clone().sub( this.v1 );
return tangent.normalize();
};
export { LineCurve };