# Coordinate System

Jump to navigation Jump to search

## Definition

For a definition see MathWorld:Coordinate System.

## Codebook

### Construction

The construction of a coordinate system is easy if a corresponding system exists in VisAD.

```visad.PolarCoordinateSystem visadPolar = new visad.PolarCoordinateSystem(visad.RealTupleType.SpatialCartesian2DTuple));
CoordinateSystem2D polar = new VisADCoordinateSystem2D(visadPolar);
```

Another way to create a coordinate system is to specify the functions describing the transformations. The following example creates the polar coordinate system according to this approach.

```IDoubleFunction2D trans0 = new DoubleFunction2D() {

public double apply(double r, double theta) {
return r * Math.cos(theta);
}

public boolean isInDomain(double r, double theta) {
return (r > 0.0 && (theta >= 0.0 && theta < 2 * Math.PI)) || (r == 0.0 && theta == 0.0);
}
};

IDoubleFunction2D trans1 = new DoubleFunction2D() {

public double apply(double r, double theta) {
return r * Math.sin(theta);
}

public boolean isInDomain(double r, double theta) {
return (r > 0.0 && (theta >= 0.0 && theta < 2 * Math.PI)) || (r == 0.0 && theta == 0.0);
}
};
```
```IDoubleFunction2D invTrans0 = new DoubleFunction2D() {

public double apply(double x, double y) {
if (x == 0.0) {
return y == 0 ? 0.0 : Math.PI * (y > 0 ? 0.5 : 1.5);
} else {
double atan = Math.atan(y / x);
return atan + Math.PI * (x < 0 ? 1.0 : (y < 0 ? 2.0 : 0.0));
}
}

public boolean isInDomain(double x, double y) {
return true;
}
};

IDoubleFunction2D invTrans1 = new DoubleFunction2D() {
public double apply(double x, double y) {
return Math.sqrt(x*x + y*y);
}

public boolean isInDomain(double x, double y) {
return true;
}
};
```

Finally, a new FunctionalCoordinateSystem2D is created and the four functions are assigned.

```FunctionalCoordinateSystem2D polar = new FunctionalCoordinateSystem2D();
polar.setToFunctions(trans0, trans1);
polar.setFromFunctions(invTrans0, invTrans1);
```

If you want to interchange the transformation and the inverse transformation, just create an instance of InverseCoordinateSystem2D

```ICoordinateSystem2D polar_inverted1 = new InverseCoordinateSystem2D(visadPolar);
ICoordinateSystem2D polar_inverted2 = new InverseCoordinateSystem2D(polar);
```

## Reference

Eric W. Weisstein: Coordinate System at MathWorld.