Skip to content

how_to_use

Olivier Massot edited this page Dec 9, 2016 · 1 revision

How to use

Geometry functions

Cell Shape: Hexagonal or square grids

Currently, pypog gives you access to geometric functions on two types of grids: hexagonal (pointy topped) or square.

Pass the grid type to geometry's functions with geometry.HEX or geometry.SQUARE

Ex: geometry.line(geometry.HEX, 0, 0, 5, 5) will return the coordinates on a line between (0,0) and (5,5), on an hexagonal grid.

2D / 3D

Some of the following functions come in 2d and 3d versions. The only difference is the additional z coordinate that come in arguments and in the resulting coordinates.

Cubic / Offset coordinates

On hexagonal grids, many algorithms use cubic coordinates

Neighbours

geometry.neighbours_of(cell_shape, x, y) will return the list of (x, y) coordinates of adjacent cells of the (x, y) cell.

Lines

geometry.line(cell_shape, x1, y1, x2, y2) will return a list of (x, y) coordinates on a line between x1, y1) and (x2, y2)

geometry.line3d(cell_shape, x1, y1, z1, x2, y2, z2) will return a list of (x, y, z) coordinates on a line between x1, y1, z1) and (x2, y2, z2)

Line algorithm is based on Bresenham's line algorithm

Zone

geometry.zone(cell_shape, x1, y1, x2, y2, radius) will return a list of the (x, y) coordinates of the cells inside a zone.

geometry.zone3d(cell_shape, x1, y1, z1, x2, y2, z2, radius) will return a list of the (x, y, z) coordinates of the cells inside a zone.

Rect

geometry.rect(cell_shape, x1, y1, x2, y2) will return a list of the (x, y) coordinates of the cells inside a rectangle. (x1, y1) is top-left corner, (x2, y2) is bottom-right corner.

Hollow Rect

geometry.hollow_rect(cell_shape, x1, y1, x2, y2): similar to geometry.rect function, but without the inside cells.

Triangle

geometry.triangle(cell_shape, xa, ya, xh, yh) returns a list of (x, y) coordinates in a triangle. (xa, ya) is the top of the triangle, (xh, yh) if the middle of the base.

geometry.triangle3d(cell_shape, xa, ya, za, xh, yh, zh) returns a list of (x, y, z) coordinates in a triangle. (xa, ya, za) is the top of the triangle, (xh, yh, zh) if the middle of the base.

Pivot

geometry.pivot(cell_shape, (x, y), [(x1, y1), (x2, y2), (x3, y3), ...], rotations) returns the list of the coordinates after a counterclockwise rotation of the list of (xn, yn) coordinates around the (x, y) center. rotations is the number of rotations.

On hexagonal grids, pivot rotates from 60° ; On square grids, pivot rotates from 90°