@@ -18,23 +18,24 @@ export const fromPointsRandom = (out, a, b, c) => {
1818 let ba = vec3 . subtract ( vec3 . create ( ) , b , a )
1919 let ca = vec3 . subtract ( vec3 . create ( ) , c , a )
2020 if ( vec3 . length ( ba ) < EPS ) {
21- ba = vec3 . orthogonal ( ba , ca )
21+ vec3 . orthogonal ( ba , ca )
2222 }
2323 if ( vec3 . length ( ca ) < EPS ) {
24- ca = vec3 . orthogonal ( ca , ba )
24+ vec3 . orthogonal ( ca , ba )
2525 }
26- let normal = vec3 . cross ( vec3 . create ( ) , ba , ca )
26+
27+ // calculate plane normal
28+ let normal = vec3 . cross ( out , ba , ca )
2729 if ( vec3 . length ( normal ) < EPS ) {
2830 // this would mean that ba == ca.negated()
29- ca = vec3 . orthogonal ( ca , ba )
30- normal = vec3 . cross ( normal , ba , ca )
31+ vec3 . orthogonal ( ca , ba )
32+ vec3 . cross ( normal , ba , ca )
3133 }
32- normal = vec3 . normalize ( normal , normal )
33- const w = vec3 . dot ( normal , a )
34+ vec3 . normalize ( normal , normal )
3435
35- out [ 0 ] = normal [ 0 ]
36- out [ 1 ] = normal [ 1 ]
37- out [ 2 ] = normal [ 2 ]
36+ // and distance
37+ const w = vec3 . dot ( normal , a )
3838 out [ 3 ] = w
39+
3940 return out
4041}
0 commit comments