# PostGIS Axis orientation BOX3D

I was wondering which axis X Y and Z point which way for PostGIS BOX3D-Objects.

I thought Z was up, X was right and Y was "back", which matches this drawing: https://gis.stackexchange.com/a/214938/120335

However, looking at the code here, I found a comment calling the side with the maximum Y front, which would mean the Y axis would point the other way.

So, is one way wrong and one way correct? Are both correct in their own ways?

## 1 Answer

You can prove this to yourself quite easily. If you create a cube with one vertex as (0, 0, 0) and another with (1, 1, 1), eg,

``````SELECT
ST_AsText(
ST_Extrude(
ST_Force3d(
ST_Expand(
ST_Makepoint(0.5, 0.5),
0.5)
),
0, 0, 1)
);
``````

You get:

POLYHEDRALSURFACE Z (((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),((0 0 1,1 0 1,1 1 1,0 1 1,0 0 1)),((0 0 0,0 0 1,0 1 1,0 1 0,0 0 0)),((0 1 0,0 1 1,1 1 1,1 1 0,0 1 0)),((1 1 0,1 1 1,1 0 1,1 0 0,1 1 0)),((1 0 0,1 0 1,0 0 1,0 0 0,1 0 0)))

and if you change ST_AsText for ST_Volume you will see the volume is 1, as expect.

If you now translate this cube, using ST_Translate, some arbitrary but different number of units along x, y, z, eg, 1, 2, and 3 units in x, y, z directions:

``````SELECT
ST_AsText(
ST_Translate(
ST_Extrude(
ST_Force3d(
ST_Expand(
ST_Makepoint(0.5, 0.5),
0.5)
),
0, 0, 1),
1, 2, 3)
);
``````

you now get a cube with one corner being (1, 2, 3) and the opposite corner being (2, 3, 4) as you would expect:

POLYHEDRALSURFACE Z (((1 2 3,1 3 3,2 3 3,2 2 3,1 2 3)),((1 2 4,2 2 4,2 3 4,1 3 4,1 2 4)),((1 2 3,1 2 4,1 3 4,1 3 3,1 2 3)),((1 3 3,1 3 4,2 3 4,2 3 3,1 3 3)),((2 3 3,2 3 4,2 2 4,2 2 3,2 3 3)),((2 2 3,2 2 4,1 2 4,1 2 3,2 2 3)))

You can do similar things with ST_RotateX, ST_RotateY and ST_RotateZ which should convince you that the x axis runs parallel to the bottom of the screen, the z parallel to the edge of the screen and the y into the screen.

• Thanks, that helped me understand it. If anyone is reading this, I'd like to add that ST_RotateX/Y/Z rotate counter-clockwise. Their documentation doesn't say that, but ST_Rotate (synonym for ST_RotateZ) had that information. – Mat2095 May 9 '18 at 20:45
• Yes, good point about the rotations. – John Powell May 9 '18 at 21:04