Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

263
Vistas
How can I rotate an arbitrary point around an arbitrary origin in Javascript

Using this question: 3D point rotation algorithm I was able to assimilate a basic rotate function for my arbitrary vector library in javascript.

The issue is, the question above doesn't explain how to rotate around any point (Like an orbit)

This vector library extends the Array object type (I originally forked it from an old project, and then adapted it for my own projects), so think of each vector like an array with extra methods and getters (You can find the whole source code here)

This is the method I use to rotate the current vector with a Vector plugged in as the angle (So each axis can be controlled separately)

It grabs the cosine and sine values required for all three axi (pitch, roll, yaw) and then stores them as three vectors in an array.

Finally it multiplies each vector into each coordinate accordingly.

    rotate(angle) {
        let cos = (angle.copy).map(val => Math.cos(angle));
        let sin = (angle.copy).map(val => Math.sin(angle));
        let other = [new Vector([
                cos.z * cos.y,
                cos.z * sin.y * sin.x - sin.z * cos.x,
                cos.z * sin.y * cos.x + sin.z * sin.x
            ]), new Vector([
                sin.z * cos.y,
                sin.z * sin.y * sin.x + cos.z * cos.x,
                sin.z * sin.y * cos.x - cos.z * sin.x
            ]), new Vector([
                -sin.y,
                cos.y * sin.x,
                cos.y * cos.x
            ])];
        let stored = point.copy;
        this.map((val, i) => (other[i].mul(stored)).sum);
    }

My main question is, how can I adapt this tool to allow me to rotate around any point in 3D space

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you have a rotation matrix R and you want to rotate a vector v around a point a you must add R with a and multiply it by the product of v times a, then the formula for the result is

 a + R * (va)

This applies the same if the matrix-vector multiplication is from the left.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda