Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8157213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:12:20+00:00 2026-06-06T17:12:20+00:00

I am using these two functions in order to rotate my objects in my

  • 0

I am using these two functions in order to rotate my objects in my three.js scenes

    // Rotate an object around an arbitrary axis in object space
    function rotateAroundObjectAxis(object, axis, radians) {
        rotationMatrix = new THREE.Matrix4();
        rotationMatrix.makeRotationAxis(axis.normalize(), radians);
        object.matrix.multiplySelf(rotationMatrix);  // post-multiply
        object.rotation.getRotationFromMatrix(object.matrix, object.scale);
        delete rotationMatrix;
    }

    // Rotate an object around an arbitrary axis in world space      
    function rotateAroundWorldAxis(object, axis, radians) {
        rotationMatrix = new THREE.Matrix4();
        rotationMatrix.makeRotationAxis(axis.normalize(), radians);
        rotationMatrix.multiplySelf(object.matrix);        // pre-multiply
        object.matrix = rotationMatrix;
        object.rotation.getRotationFromMatrix(object.matrix, object.scale);
        delete rotationMatrix;
    }

where rotationMatrix is a global variable. I am unexperienced with Javascript and web app development, but I talked to someone who seemed to convey to me that because sometimes I call these functions once a frame I should be concerned about the fact that it creates new objects each call. This has not given me problems so far, but should I be concerned that the garbage collector will not be able to keep up eventually? I understand that the delete keyword here unlike in C++ only deletes the reference. Does this help when I call it at the end of each function? Also is there anything I can do other than that to make this function more efficient so that it can be called as many times as possible without slowing things down or eventually making the browser take up too much memory.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T17:12:22+00:00Added an answer on June 6, 2026 at 5:12 pm

    After fiddling with this a bit further I have learned a lot about how to use the Chrome Developer Tools. Also I have rewritten these functions to be what I feel could be slightly more efficient. I will have to see how it scales, but the profiling tools seem to show that these are a bit better on memory and the garbage collector.

    The function for rotating in world space however requires a copy in order not to create a new matrix. In short if we do not create a new matrix each call, we cannot simply copy the reference, we must copy the matrix. Basically it comes down to whether or not this copy or the garbage collector overhead is going to be more expensive.

    // Rotate an object around an arbitrary axis in object space
    var rotObjectMatrix= new THREE.Matrix4();
    function rotateAroundObjectAxis(object, axis, radians) {
        rotObjectMatrix.makeRotationAxis(axis.normalize(), radians);
        object.matrix.multiplySelf(rotObjectMatrix);      // post-multiply
        object.rotation.getRotationFromMatrix(object.matrix, object.scale);
    }
    
    var rotWorldMatrix = new THREE.Matrix4();
    // Rotate an object around an arbitrary axis in world space       
    function rotateAroundWorldAxis(object, axis, radians) {
        rotWorldMatrix.makeRotationAxis(axis.normalize(), radians);
        rotWorldMatrix.multiplySelf(object.matrix);        // pre-multiply
        object.matrix.copy(rotWorldMatrix);
        object.rotation.getRotationFromMatrix(object.matrix, object.scale);
    }
    

    I am not sure whether this will be better or not. I took these screenshots. This one was using the original functions and this one is with these new functions. Seems to suggest slightly better performance with the new ones. I’m not sure if I can notice a difference.

    EDIT: I came up with a different function once I became aware of the updateMatrix function. This avoids the use of copying the entire matrix. Here is the new world rotation function:

    /** Adds a rotation of rad to the obj's rotation about world's axis */
    var rotWorldMatrix = new THREE.Matrix4();
    function rotateWorldAxis(obj, axis, rad) {
        rotWorldMatrix.makeRotationAxis(axis.normalize(), rad);
        obj.updateMatrix();
        rotWorldMatrix.multiplySelf(obj.matrix); // pre-multiply
        obj.rotation.getRotationFromMatrix(rotWorldMatrix, obj.scale);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

t = Time.now d = 10.minutes.from_now Using these two variables, how do I output
What is the difference between these two: font-style:italic font-style:oblique I tried using the W3Schools
I have two tables (using table variables for illustration. You can run these directly
Suppose we have an object that can be sorted using two or more comparison
I have two functions named ChangeText() & ChangeColor(), the first function called ChangeText who
I'm using these two methods to create orders programmatically in Magento. The first one
I have two table functions that return a single column each. One function is
I am using servlet there is two method redirect and forward both are send
Consider there are two wi-fk networks A & B using the same channel and
what does it mean where there are two id's in the jquery selector using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.