Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

261
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!