1 | /**
|
---|
2 | * @author bhouston / http://exocortex.com
|
---|
3 | */
|
---|
4 |
|
---|
5 | THREE.Line3 = function ( start, end ) {
|
---|
6 |
|
---|
7 | this.start = ( start !== undefined ) ? start : new THREE.Vector3();
|
---|
8 | this.end = ( end !== undefined ) ? end : new THREE.Vector3();
|
---|
9 |
|
---|
10 | };
|
---|
11 |
|
---|
12 | THREE.Line3.prototype = {
|
---|
13 |
|
---|
14 | constructor: THREE.Line3,
|
---|
15 |
|
---|
16 | set: function ( start, end ) {
|
---|
17 |
|
---|
18 | this.start.copy( start );
|
---|
19 | this.end.copy( end );
|
---|
20 |
|
---|
21 | return this;
|
---|
22 |
|
---|
23 | },
|
---|
24 |
|
---|
25 | copy: function ( line ) {
|
---|
26 |
|
---|
27 | this.start.copy( line.start );
|
---|
28 | this.end.copy( line.end );
|
---|
29 |
|
---|
30 | return this;
|
---|
31 |
|
---|
32 | },
|
---|
33 |
|
---|
34 | center: function ( optionalTarget ) {
|
---|
35 |
|
---|
36 | var result = optionalTarget || new THREE.Vector3();
|
---|
37 | return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
|
---|
38 |
|
---|
39 | },
|
---|
40 |
|
---|
41 | delta: function ( optionalTarget ) {
|
---|
42 |
|
---|
43 | var result = optionalTarget || new THREE.Vector3();
|
---|
44 | return result.subVectors( this.end, this.start );
|
---|
45 |
|
---|
46 | },
|
---|
47 |
|
---|
48 | distanceSq: function () {
|
---|
49 |
|
---|
50 | return this.start.distanceToSquared( this.end );
|
---|
51 |
|
---|
52 | },
|
---|
53 |
|
---|
54 | distance: function () {
|
---|
55 |
|
---|
56 | return this.start.distanceTo( this.end );
|
---|
57 |
|
---|
58 | },
|
---|
59 |
|
---|
60 | at: function ( t, optionalTarget ) {
|
---|
61 |
|
---|
62 | var result = optionalTarget || new THREE.Vector3();
|
---|
63 |
|
---|
64 | return this.delta( result ).multiplyScalar( t ).add( this.start );
|
---|
65 |
|
---|
66 | },
|
---|
67 |
|
---|
68 | closestPointToPointParameter: function() {
|
---|
69 |
|
---|
70 | var startP = new THREE.Vector3();
|
---|
71 | var startEnd = new THREE.Vector3();
|
---|
72 |
|
---|
73 | return function ( point, clampToLine ) {
|
---|
74 |
|
---|
75 | startP.subVectors( point, this.start );
|
---|
76 | startEnd.subVectors( this.end, this.start );
|
---|
77 |
|
---|
78 | var startEnd2 = startEnd.dot( startEnd );
|
---|
79 | var startEnd_startP = startEnd.dot( startP );
|
---|
80 |
|
---|
81 | var t = startEnd_startP / startEnd2;
|
---|
82 |
|
---|
83 | if ( clampToLine ) {
|
---|
84 |
|
---|
85 | t = THREE.Math.clamp( t, 0, 1 );
|
---|
86 |
|
---|
87 | }
|
---|
88 |
|
---|
89 | return t;
|
---|
90 |
|
---|
91 | };
|
---|
92 |
|
---|
93 | }(),
|
---|
94 |
|
---|
95 | closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
|
---|
96 |
|
---|
97 | var t = this.closestPointToPointParameter( point, clampToLine );
|
---|
98 |
|
---|
99 | var result = optionalTarget || new THREE.Vector3();
|
---|
100 |
|
---|
101 | return this.delta( result ).multiplyScalar( t ).add( this.start );
|
---|
102 |
|
---|
103 | },
|
---|
104 |
|
---|
105 | applyMatrix4: function ( matrix ) {
|
---|
106 |
|
---|
107 | this.start.applyMatrix4( matrix );
|
---|
108 | this.end.applyMatrix4( matrix );
|
---|
109 |
|
---|
110 | return this;
|
---|
111 |
|
---|
112 | },
|
---|
113 |
|
---|
114 | equals: function ( line ) {
|
---|
115 |
|
---|
116 | return line.start.equals( this.start ) && line.end.equals( this.end );
|
---|
117 |
|
---|
118 | },
|
---|
119 |
|
---|
120 | clone: function () {
|
---|
121 |
|
---|
122 | return new THREE.Line3().copy( this );
|
---|
123 |
|
---|
124 | }
|
---|
125 |
|
---|
126 | };
|
---|