Three.js: How about adding the makeScaleAlong method to the matrix4?

Created on 11 Jun 2020  Â·  3Comments  Â·  Source: mrdoob/three.js

// matrix that scales along normalized vector n by scale value k
Matrix4.prototype.makeScaleAlong = function ( n, k ) {
    var _k = k-1;
    var xy = n.x * n.y;
    var xz = n.x * n.z;
    var yz = n.y * n.z;
    var xAxis = new Vector3(
      1 + _k * n.x * n.x,
        _k * xy,
        _k * xz
    );
    var yAxis = new Vector3(
        _k * xy,
        1 + _k * n.y * n.y,
        _k * yz
    );
    var zAxis = new Vector3(
        _k * xz,
        _k * yz,
        1 + _k * n.z * n.z
    );
    return this.makeBasis(xAxis, yAxis, zAxis);
};

All 3 comments

I'm afraid this method is way to use-case specific.

Out of curiosity: Do you have some sort of reference this code is based on?

Calculate the miter of TubeGeometry.
image
image

Thanks for sharing the code. But as long as no more people request such a method, it's more appropriate to not include in the library.

Please keep in mind that three.js is not a math library. The existing math API represents the a set of methods frequently used in the library and app level code.

Was this page helpful?
0 / 5 - 0 ratings