Skip to content

The Vec3.rotateN is wrong. #16553

@jykgod

Description

@jykgod

Cocos Creator version

3.8.0

System information

Windows10

Issue description

Vec3.rotateN is wrong.

 public static rotateN<Out extends IVec3Like> (out: Out, v: IVec3Like, o: IVec3Like, n: IVec3Like, a: number): Out {
        // Translate point to the origin
        const x = v.x - o.x;
        const y = v.y - o.y;
        const z = v.z - o.z;

        // perform rotation
        const nx = n.x;
        const ny = n.y;
        const nz = n.z;

        const cos = Math.cos(a);
        const sin = Math.sin(a);
        const rx = x * (nx * nx * (1.0 - cos) + cos) + y * (nx * ny * (1.0 - cos) - nx * sin) + z * (nx * nz * (1.0 - cos) + ny * sin);
        const ry = x * (nx * ny * (1.0 - cos) + nz * sin) + y * (ny * ny * (1.0 - cos) + cos) + z * (ny * nz * (1.0 - cos) - nx * sin);
        const rz = x * (nx * nz * (1.0 - cos) - ny * sin) + y * (ny * nz * (1.0 - cos) + nx * sin) + z * (nz * nz * (1.0 - cos) + cos);

        // translate to correct position
        out.x = rx + o.x;
        out.y = ry + o.y;
        out.z = rz + o.z;

        return out;
    }

The "const rx = x * (nx * nx * (1.0 - cos) + cos) + y * (nx * ny * (1.0 - cos) - nx * sin) + z * (nx * nz * (1.0 - cos) + ny * sin);"
should be " const rx = x * (nx * nx * (1.0 - cos) + cos) + y * (nx * ny * (1.0 - cos) - nz * sin) + z * (nx * nz * (1.0 - cos) + ny * sin);"

Relevant error log output

No response

Steps to reproduce

Vec3.rotateX(v, new Vec3(0, 1, 0), Vec3.ZERO,  0.5);
 console.log(v);
Vec3.rotateN(v, new Vec3(0, 1, 0), Vec3.ZERO, new Vec3(1,0,0), 0.5);
 console.log(v);

Minimal reproduction project

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions