public class SphericalHarmonicCoefficients extends Object implements IEquatable<SphericalHarmonicCoefficients>, ICloneWithContext
Modifier | Constructor and Description |
---|---|
|
SphericalHarmonicCoefficients(double[] zonalCoefficients,
double[][] cosineCoefficients,
double[][] sineCoefficients)
Initializes a new instance from the provided coefficients.
|
|
SphericalHarmonicCoefficients(int degree,
int order)
Initializes a new instance according to the provided parameters.
|
protected |
SphericalHarmonicCoefficients(SphericalHarmonicCoefficients existingInstance,
CopyContext context)
Initializes a new instance as a copy of an existing instance.
|
Modifier and Type | Method and Description |
---|---|
Object |
clone(CopyContext context)
Clones this object using the specified context.
|
boolean |
equals(Object obj)
Indicates whether another object is exactly equal to this instance.
|
static boolean |
equals(SphericalHarmonicCoefficients left,
SphericalHarmonicCoefficients right)
Returns
true if the two instances are exactly equal. |
boolean |
equalsType(SphericalHarmonicCoefficients other)
Indicates whether another instance of this type is exactly equal to this instance.
|
double[][] |
getCosineCoefficients()
Gets the array of cosine coefficients (m= [1, L])
|
int |
getDegree()
Gets the maximum degree of the spherical harmonic coefficients.
|
int |
getOrder()
Gets the maximum order of the spherical harmonic coefficients.
|
double[][] |
getSineCoefficients()
Gets the array of sine coefficients (m= [1, L])
|
double[] |
getZonalCoefficients()
Gets the array of zonal coefficients (the negative of the cosine coefficients for m=0; J2 = -C20, J3 = -C30, etc.).
|
int |
hashCode()
Returns a hash code for this instance, which is suitable for use in hashing algorithms and data structures like a hash table.
|
static boolean |
notEquals(SphericalHarmonicCoefficients left,
SphericalHarmonicCoefficients right)
Returns
true if the two instances are not exactly equal. |
public SphericalHarmonicCoefficients(int degree, int order)
degree
- The degree of the coefficient set.order
- The order of the coefficient set.public SphericalHarmonicCoefficients(@Nonnull double[] zonalCoefficients, @Nonnull double[][] cosineCoefficients, @Nonnull double[][] sineCoefficients)
An consistent field of degree 2 and order 0 would be inferred from a zonalCoefficients array that is size double[3] with cosineCoefficients array that is size double[3][] with cosineCoefficients[0] a double[1], cosineCoefficients[1] a double[1], and cosineCoefficients[2] a double[1]. The sineCoefficients array must be the same size and shape as the cosineCoefficients array. All of the values inside the cosine and sine coefficient arrays should be 0.0 if the order is 0, but this is not enforced. The cosine coefficients are 0.0 because the zonal coefficients incorporate the order 0 terms as J2 = -C20, J3 = -C30, etc. The sine coefficients S20, S30, etc. are 0.0 by definition.
A consistent field of degree 2 and order 1 would be inferred from a zonalCoefficients array that is size double[3] with cosineCoefficients array that is size double[3][] with cosineCoefficients[0] a double[1], cosineCoefficients[1] a double[2], and cosineCoefficients[2] a double[2]. The sineCoefficients array must be the same size and shape as the cosineCoefficients array. Any field with degree greater than 2 and order 1 would have any cosineCoefficients[3] and higher as double[2] as well. The order 0 terms of the cosine and sine arrays should be 0.0 (e.g. sineCoefficients[2][0] == 0.0), but the higher-order terms are typically non-zero (e.g. cosineCoefficients[2][1] != 0.0).
A consistent field of degree and order 2 would be inferred from a zonalCoefficients array that is size double[3] with cosineCoefficients array that is size double[3][] with cosineCoefficients[0] a double[1], cosineCoefficients[1] a double[2], and cosineCoefficients[2] a double[3]. The sineCoefficients array must be the same size and shape as the cosineCoefficients array. Any field with equal degrees and orders would have linearly increasing sizes of the inner double arrays. For example, a gravity field of degree and order 3 would have its cosineCoefficient[3] a double[4].
zonalCoefficients
- The zonal coefficients (J2 = -C20, J3 = -C30, etc.).cosineCoefficients
- The cosine coefficients (C21, C22, C31, etc.).sineCoefficients
- The sine coefficients (S21, S22, S31, etc.).ArgumentNullException
- Thrown when zonalCoefficients
, cosineCoefficients
,
or sineCoefficients
are null.ArgumentException
- Thrown when the input coefficient arrays have inconsistent sizes or shapes with each other
or with the inferred degree and order of the field.protected SphericalHarmonicCoefficients(@Nonnull SphericalHarmonicCoefficients existingInstance, @Nonnull CopyContext context)
See ICloneWithContext.clone(CopyContext)
for more information about how to implement this constructor
in a derived class.
existingInstance
- The existing instance to copy.context
- A CopyContext
that controls the depth of the copy.ArgumentNullException
- Thrown when existingInstance
or context
is null
.public final Object clone(CopyContext context)
This method should be implemented to call a copy constructor on the class of the
object being cloned. The copy constructor should take the CopyContext
as a parameter
in addition to the existing instance to copy. The copy constructor should first call
CopyContext.addObjectMapping(T, T)
to identify the newly constructed instance
as a copy of the existing instance. It should then copy all fields, using
CopyContext.updateReference(T)
to copy any reference fields.
A typical implementation of ICloneWithContext
:
public static class MyClass implements ICloneWithContext {
public MyClass(MyClass existingInstance, CopyContext context) {
context.addObjectMapping(existingInstance, this);
someReference = context.updateReference(existingInstance.someReference);
}
@Override
public final Object clone(CopyContext context) {
return new MyClass(this, context);
}
private Object someReference;
}
In general, all fields that are reference types should be copied with a call to
CopyContext.updateReference(T)
. There are a couple of exceptions:
If one of these exceptions applies, the CopyContext
should be given an opportunity
to update the reference before the reference is copied explicitly. Use
CopyContext.updateReference(T)
to update the reference. If CopyContext.updateReference(T)
returns
the original object, indicating that the context does not have a replacement registered,
then copy the object manually by invoking a Clone method, a copy constructor, or by manually
constructing a new instance and copying the values.
alwaysCopy = context.updateReference(existingInstance.alwaysCopy);
if (existingInstance.alwaysCopy != null && alwaysCopy == existingInstance.alwaysCopy) {
alwaysCopy = (AlwaysCopy) existingInstance.alwaysCopy.clone(context);
}
If you are implementing an evaluator (a class that implements IEvaluator
), the
IEvaluator.updateEvaluatorReferences(agi.foundation.infrastructure.CopyContext)
method shares some responsibilities with the
copy context constructor. Code duplication can be avoided by doing the following:
CopyContext.updateReference(T)
. You should still call CopyContext.updateReference(T)
on any references to
non-evaluators.
IEvaluator.updateEvaluatorReferences(agi.foundation.infrastructure.CopyContext)
as the last line in the constructor and pass it the
same CopyContext
passed to the constructor.
IEvaluator.updateEvaluatorReferences(agi.foundation.infrastructure.CopyContext)
as normal. See the reference documentation for
IEvaluator.updateEvaluatorReferences(agi.foundation.infrastructure.CopyContext)
for more information on implementing that method.
public MyClass(MyClass existingInstance, CopyContext context) {
super(existingInstance, context);
someReference = context.updateReference(existingInstance.someReference);
evaluatorReference = existingInstance.evaluatorReference;
updateEvaluatorReferences(context);
}
@Override
public void updateEvaluatorReferences(CopyContext context) {
evaluatorReference = context.updateReference(evaluatorReference);
}
@Override
public Object clone(CopyContext context) {
return new MyClass(this, context);
}
private Object someReference;
private IEvaluator evaluatorReference;
clone
in interface ICloneWithContext
context
- The context to use to perform the copy.public final int getDegree()
public final int getOrder()
@Nonnull public final double[] getZonalCoefficients()
@Nonnull public final double[][] getCosineCoefficients()
@Nonnull public final double[][] getSineCoefficients()
public boolean equals(Object obj)
equals
in class Object
obj
- The object to compare to this instance.true
if obj
is an instance of this type and represents the same value as this instance; otherwise false
.Object.hashCode()
,
HashMap
public final boolean equalsType(SphericalHarmonicCoefficients other)
equalsType
in interface IEquatable<SphericalHarmonicCoefficients>
other
- The instance to compare to this instance.true
if other
represents the same value as this instance; otherwise false
.public int hashCode()
hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public static boolean equals(SphericalHarmonicCoefficients left, SphericalHarmonicCoefficients right)
true
if the two instances are exactly equal.left
- The instance to compare to right
.right
- The instance to compare to left
.true
if left
represents the same value as right
; otherwise false
.public static boolean notEquals(SphericalHarmonicCoefficients left, SphericalHarmonicCoefficients right)
true
if the two instances are not exactly equal.left
- The instance to compare to right
.right
- The instance to compare to left
.true
if left
does not represent the same value as right
; otherwise false
.