Giter VIP home page Giter VIP logo

Comments (6)

WestLangley avatar WestLangley commented on May 18, 2024 3

@chenxinhang12345 Do this:

const v1 = new THREE.Vector3().setFromSpherical( s1 );

from three.js.

WestLangley avatar WestLangley commented on May 18, 2024 1

... because Spherical and Cylindrical coordinates are not unique, just as 2D polar coordinates are not unique.

const s1 = new THREE.Spherical( 1, 0, 0 );
const s2 = new THREE.Spherical( 1, 0, 2 * Math.PI );

Likewise, quaternion.equals( q ) is also incorrect because quaternions are not unique.

//

As a side note, I am not in favor of methods that compare floating point values using equality. I would have preferred

Vector3.equals( vector, tolerance = 0 ).

from three.js.

WestLangley avatar WestLangley commented on May 18, 2024

Spherical and Cylindrical coordinates are not unique, and neither class has an equals() method.

Can you please explain your use case?

from three.js.

chenxinhang12345 avatar chenxinhang12345 commented on May 18, 2024

Yeah you are right. Those classes shouldn't have .equals methods.

from three.js.

Mugen87 avatar Mugen87 commented on May 18, 2024

Spherical and Cylindrical coordinates are not unique, and neither class has an equals() method.

Do you mind explaining this in more detail? Why can we compare euclidian coordinates but not spherical ones? The following does work as expected:

const v1 = new THREE.Vector3( 1, 0, 0 );
const v2 = new THREE.Vector3( 1, 0, 0 );
console.log( v1.equals( v2 ) ); // true

const s1 = new THREE.Spherical().setFromVector3( v1 );
const s2 = new THREE.Spherical().setFromVector3( v2 );
console.log( equals( s1, s2 ) ); // true
 
function equals( s1, s2 ) {

	return ( ( s1.radius === s2.radius ) && ( s1.phi === s2.phi ) && ( s1.theta === s2.theta ) );

}

Demo: https://jsfiddle.net/8fbkpr60/1/

from three.js.

chenxinhang12345 avatar chenxinhang12345 commented on May 18, 2024

Instead of adding .equals(), would it be a good idea to add toVector3() so that we could compare the derived Euclidian coordinates?

from three.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.