geom module

This module contains all classes and methods used for geometric calculations. pLAySVG has one unconventional term it uses in its geometric calculations: ‘angal’. An angal is a fractional representation of an angle such that (using the clock metaphor) 0 is at 12:00, 0.25 is at 3:00, 0.5 is at 6:00, and 0.75 is at 9:00. An angal is always in range |0 - 1( as whole number portions of numbers are truncated in any calculations using them.

class geom.Point(xval=0, yval=0)[source]

A 2D cartesian point

convertToPoler()[source]

returns a pair (distance from center, angal)

getMultiple(scalar)[source]

returns Point(self.x*scalar, self.y*scalar)

polerInit(radius, angal)[source]

initialize the x and y values based upon radial co-ordinates, with the angal representing the angle as in Angal class

strForPoly()[source]

used to output 2D points for OpenSCAD

strOnPlane()[source]

used to output 3D points for OpenSCAD

unitVector()[source]

returns unit vector Point

vectorLength()[source]

returns length of point as vector

geom.aNum(theNum)[source]

used to output fixed decimal string of length 5 (magic number) for SVG output

geom.angalBetween(ptA, ptB, ptC)[source]

calculates the angal for angle ABC

geom.angalOfPoints(pointA, pointB)[source]

calculates the angal of line AB

geom.createOffsetRadialGrid(rings, spokes, layerSpacing, beginRadius)[source]

creates a radial grid with staggered layers as array containing arrays of Point objects where the returned array is accessed as follows: plots[layer][angle], where increase in layer moves out from center, increase in angle moves clockwise odd layer has point directly above center, even layer does not starting position for angle=0 varies based upon layer, spiraling clockwise

geom.createRadialGrid(rings, spokes, layerSpacing, beginRadius)[source]

creates a radial grid with staggered layers as array containing arrays of Point where returns array is accessed as follows: plots[layer][angle], where increase in layer moves out from center, increase in angle moves clockwise

geom.createRadialPlots(position, radius, spokes, passive=0)[source]

returns an array of equidistant points on a circle

geom.createTriangleCentreGrid(startPoint, sideLength, levels)[source]

creates a 2D array representing centres of triangles in a triangular grid bound by a triangle first dimension represents height second dmension represents horizontal position

geom.createTriangularGrid(startPoint, sideLength, levels)[source]

creates a 2D array representing intersections of a triangular grid bound by a triangle first dimension represents height, second dimension represents horizontal position

geom.cubicBezierLength(P1, P2, P3, P4, maxLev=10)[source]

calculate the length of a cubic bezier start:P1 control1:P2 control2:P3 end:P4

geom.distanceBetween(pointA, pointB)[source]

returns distance between pointA and pointB

geom.distanceBetweenPoints(points)[source]

returns the sum of succesive distances between elements in the array points

geom.generateStarDict(limit)[source]

generate a dictionary representing all possible irregular star polygons

geom.getAngalBetween(pointA, pointB, pointC)[source]

Returns the angal defined for ABC (DUPLICATE ?)

geom.getDiscreteCubicBezier(pointA, pointB, pointC, pointD, n)[source]

Accepts 4 point objects representing a cubic bezier curve as described on wikipedia and a number of points n and returns an array of n CartesianPoints equally spaced along that curve

geom.getDiscreteQuadradicBezier(pointA, pointB, pointC, n)[source]

Accepts 4 point objects representing a quadradic bezier curve as described on wikipedia and a number of points n and returns an array of n CartesianPoints equally spaced along that curve

geom.getLineDivision(pointA, pointB, fract)[source]

returns a point that is fract percent of the distance from pointA to pointB

geom.getLineDivisionDistance(pointA, pointB, distance)[source]

get a point of specific distance along the line from pointA to pointB

geom.getLineDivisions(pointA, pointB, n)[source]

returns an array of n points equally spaced along line AB

geom.getMidpoint(pointA, pointB)[source]

returns midpoint between pointA and pointB

geom.intersectLineLine(a1, a2, b1, b2)[source]

returns the itersection point for 2 lines if there exists one, calculations ported from Kevin Lindsey’s 2D.js library (switched to Inkscape extensions’ summersnight.py algorithm)

geom.perspectiveDistanceRatioArray(angal, divisions)[source]

In a perspective drawing, things which are equally spaced apart in 3 dimensions, (i.e. mailboxes infront of houses on a road) get closer and closer together this algorithm, given a number of divisions and an angle at which the viewer is looking down, returns an array of ratios that represent how far each successive point is along the line towards the origin see The Illusion of Depth for an illustration. See in scripts/ platonicEarth.svg for an example of its use

geom.projectionPointOnLine(pointB, lineA, lineB)[source]

returns a point that is the projection of pointB onto line that intersects lineA and lineB

geom.quadradicBezierLength(P1, P2, P3, maxLev=10)[source]

calculate the length of a cubic bezier start:P1 control:P2 end:P3

geom.reflectPointInLine(point, lineStart, lineEnd)[source]

Calculation as described in mathworld Reflection entry

Previous topic

Basic tutorial

Next topic

document module

This Page