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

  • Home
  • SEARCH
  • 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 4561640
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:06:11+00:00 2026-05-21T18:06:11+00:00

Is quaternion comparison possible? I’m writing a Java class of Quaternions and I want

  • 0

Is quaternion comparison possible? I’m writing a Java class of Quaternions and I want to implement the Comparable interface to use the Collections.sort(List<Quaternion>) facility. I’m not expert at math, I really don’t understand the things I read about Quaternions. So, can anyone tell me can I override the compareTo method for Quaternions and how?

My class declarition:

public class Quaternion implements Serializable, Comparable<Quaternion> {

    private double s; // scalar part
    private double i, j, k; // vectorel part


    public Quaternion() {
        super();
    }

    public Quaternion(double s, double i, double j, double k) {
        super();
        this.s = s;
        this.i = i;
        this.j = j;
        this.k = k;
    }
  • 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-05-21T18:06:12+00:00Added an answer on May 21, 2026 at 6:06 pm

    There is no reason why you can’t compare two quaternions. Assuming that you want to compare magnitudes, compute and compare the Quaternion Norms. Your Quaternion class should have a norm (magnitude) method allowing a toCompare to be something like the following:

    int compareTo(Quaternion o){
      return (int)(this.norm() - o.norm());
    }
    

    A better version would be:

    int compareTo(Quaternion o){
      // return (int)(this.norm() - o.norm());
      double tNorm = this.norm;
      double oNorm = o.norm;
      int retVal = 0;
    
      if (tNorm < oNorm){
        retVal = -1;
      } else if (tNorm > oNorm){
        retVal = 1;
      }
    
      return retVal;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to initializate a class like this? Quaternion::Quaternion(){ //default without arguments Quaternion(0.,V3(0.,0.,0.));
I am working on L-system interpreter and I use quaternion as internal representation of
I defined a class like this: Quaternion& conjugate(); //negates the vector component of the
Say a object's orientation is represented by a quaternion. If I want to rotate
I want to multiply 2 quaternions, which are stored in a cv::Mat structure. I
I know that quaternions need to be normalized if I want to rotate a
I have a camera quaternion (a,b,c,d) and a cam position (camX, camY, camZ) I
I followed the question here Quaternion math for rotation? to get an angle of
Is there an existing algorithm for converting a quaternion representation of a rotation to
I'm using lib glm ( http://glm.g-truc.net/ ) for test quaternion but I've a problem;

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.