Skip to content

Commit 23d8557

Browse files
gkjohnsonMugen87
andauthored
Triangle.getInterpolation: Return null if triangle is degenerate (#27331)
* Return null if triangle is degenerate * Update docs * Ensure we support for vector4 and vector2 * Update Triangle.html --------- Co-authored-by: Michael Herzog <[email protected]>
1 parent 4ec8560 commit 23d8557

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

docs/api/en/math/Triangle.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ <h3>
9797
[page:Vector3 target] — the result will be copied into this Vector3.<br /><br />
9898

9999
Return a [link:https://en.wikipedia.org/wiki/Barycentric_coordinate_system barycentric coordinate]
100-
from the given vector. Returns null if the triangle is degenerate.<br /><br />
100+
from the given vector. Returns `null` if the triangle is degenerate.<br /><br />
101101

102102
[link:http://commons.wikimedia.org/wiki/File:Barycentric_coordinates_1.png Picture of barycentric coordinates]
103103
</p>
@@ -137,7 +137,7 @@ <h3>
137137
[page:Vector target] — Result will be copied into this Vector.<br /><br />
138138

139139
Returns the value barycentrically interpolated for the given point on the
140-
triangle.
140+
triangle. Returns `null` if the triangle is degenerate.
141141
</p>
142142

143143
<h3>[method:Boolean intersectsBox]( [param:Box3 box] )</h3>

src/math/Triangle.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,15 @@ class Triangle {
103103

104104
static getInterpolation( point, p1, p2, p3, v1, v2, v3, target ) {
105105

106-
this.getBarycoord( point, p1, p2, p3, _v3 );
106+
if ( this.getBarycoord( point, p1, p2, p3, _v3 ) === null ) {
107+
108+
target.x = 0;
109+
target.y = 0;
110+
if ( 'z' in target ) target.z = 0;
111+
if ( 'w' in target ) target.w = 0;
112+
return null;
113+
114+
}
107115

108116
target.setScalar( 0 );
109117
target.addScaledVector( v1, _v3.x );

0 commit comments

Comments
 (0)