Version: Unity 6.4 Alpha (6000.4)
LanguageEnglish
  • C#

Quaternion.Equals

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual

Declaration

public bool Equals(object other);

Declaration

public bool Equals(Quaternion other);

Parameters

Parameter Description
other The quaternion to compare with.

Returns

bool true if the quaternion components (x, y, z, w) are exactly equal.

Description

Performs exact binary comparison of each Quaternion component (x, y, z, w).

The key comparison characteristics:

  • Exact copies: Returns true when quaternions are identical copies.
  • Floating-point precision: Returns false even for tiny differences due to floating-point arithmetic.
  • Mathematically equivalent rotations: Returns false for rotations that represent the same orientation but have different component values.

For practical rotation comparison, consider using the == operator instead, which uses dot product with tolerance for approximate equality.

using UnityEngine;

public class QuaternionEqualsExample : MonoBehaviour { void Start() { // Exact copies - Equals() returns true Quaternion q1 = Quaternion.identity; Quaternion q2 = q1; Debug.Log($"Exact copies - Equals(): {q1.Equals(q2)}"); // True // Small floating point differences - Equals() returns false Quaternion q3 = Quaternion.Euler(90f, 0f, 0f); Quaternion q4 = Quaternion.Euler(90.0001f, 0f, 0f); Debug.Log($"Small difference - Equals(): {q3.Equals(q4)}"); // False Debug.Log($"Small difference - == operator: {q3 == q4}"); // True (tolerance-based) // Combine both methods for robust comparison Debug.Log($"Combined check: {q3.Equals(q4) || (q3 == q4)}"); // True } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961