pgSphere provides some casting
operators. So, you can transform an object to another data
type. A cast is done using a `CAST(x AS typename)`,
`x::typename` or `typename(x)`
construct.

**Table 2. Castings**

casting argument | type target | returns |
---|---|---|

spoint | scircle | circle with center position spoint and radius 0.0 |

spoint | sellipse | an ellipse at position spoint and radius 0.0 |

spoint | sline | a line with length 0.0 at position spoint |

scircle | sellipse | the scircle as sellipse |

sline | strans | the Euler transformation of sline |

sellipse | scircle | the bounding circle of sellipse |

sellipse | strans | the Euler transformation of sellipse |

All data types of pgSphere have
equality operators. The equality operator is as in
`SQL` `=`. Furthermore,
there are two valid negators to indicate that two objects
are not equal: `!=` and
`<>`.

On sphere, an equality relationship is rarely used. There
are frequently questions like *Is object
a contained by object
b?* or

**Table 3. Contain and overlap operators**

operator | operator returns true, if |
---|---|

@ | the left object is contained by right object |

˜ | the left object contains right object |

!@ | the left object is not contained by right object |

!˜ | the left object does not contain right object |

&& | the objects overlap each other |

!&& | the objects do not overlap each other |

An overlap or contain operator does not exist for all combinations of data types. For instance, scircle @ spoint is useless because a spherical point can never contain a spherical circle.

Another binary relationship is *crossing*.
pgSphere supports only crossing of
lines.
The correlative operator is named `#`.

The binary distance operator `<->` is
a non-boolean operator returning the distance between two
objects in radians. Currently,
pgSphere supports only distances
between points, circles, and between point and circle. If the
objects are overlapping, the distance operator returns zero
(0.0).

The length/circumference operator `@-@` is
a non-boolean unary operator returning the cirumference or
length of an object. In the current implementation,
pgSphere supports only
circumferences of circles, polygons, and boxes. It supports
lengths of lines and paths too. Instead of using the
operator, you can use the functions
`circum(object)` or
`length(object)`.

The center operator `@@` is a non-boolean
unary operator returning the center of an object. In the
current implementation of pgSphere,
only centers of circles and ellipses are supported. Instead
of using the operator, you can use the function
`center(object)`.

The unary operator `-` changes the
direction of sline or spath
objects. You can use it with a Euler transformation object
in the figurative sense, too (Section 5.10).

The unary operator `!` turns the
path of sline objects, but preserves
begin and end of the spherical line. The length of
returned line will be 360° minus the line length
of operator's argument.

The operator `!` returns
`NULL`, if the length of sline argument
is 0, because the path of returned sline
is undefined.

**Example 33. Return length and Check if north pole on slines**

sql> SELECT set_sphere_output('DEG'); set_sphere_output ------------------- SET DEG (1 row) sql> SELECT length ( sline ( spoint '(0d,0d)', spoint '(0d,10d)' ) ) * 180.0 / pi() AS length; length -------- 10 (1 row) sql> SELECT spoint '(0d,90d)' @ sline ( spoint '(0d,0d)', spoint '(0d,10d)' ) AS test; test ------ f (1 row) sql> SELECT length ( ! sline ( spoint '(0d,0d)', spoint '(0d,10d)' ) ) * 180.0 / pi() AS length; length -------- 350 (1 row) sql> SELECT spoint '(0d,90d)' @ ! sline ( spoint '(0d,0d)', spoint '(0d,10d)' ) AS test; test ------ t (1 row) |

As in a plane, translations and rotations are needed to do object or coordinate transformations. With pgSphere, it is done using Euler transformations (strans). On a sphere, there aren't real translations. All movements on a sphere are rotations around axes.

The general syntax for a transformation is always:

object operator euler |

where operators are `+` for a usual
transformation, `-` for an inverse
transformation. You can transform any object having a
pgSphere data type, except the
data type sbox.

**Example 34. Transformation of a point**

Rotate a spherical point counterclockwise, first 90° around
the `x`-axis, second 90° around
the `z`-axis, and last 40.5° around
the `x`-axis.

sql> SELECT set_sphere_output('DEG'); set_sphere_output ------------------- SET DEG (1 row) sql> SELECT spoint '(30d,0d)' + strans '90d, 90d, 40.5d, XZX AS spoint'; spoint --------------- (90d , 70.5d) (1 row) |

You can use the `+` and
`-` operator as unary operators for
transformations, too. `+strans`
just returns the transformation itself,
`-strans` returns the inverse
transformation.