Graphics-Penplotter-GcodeXY
view release on metacpan or search on metacpan
Pre-multiply the projection matrix stored by `set_perspective()` or
`set_frustum()` into the 3-D CTM (CTM := P x CTM).
After this call every subsequent `transform_point()` applies the full
view + projection pipeline, and `flatten_to_2d()` yields
perspective-correct 2-D coordinates.
Croaks if neither `set_perspective()` nor `set_frustum()` has been called.
- get\_projection()
Return the 4x4 projection matrix stored by the most recent
`set_perspective()` or `set_frustum()` call, or `undef` if none has been
set. The matrix is an arrayref of four arrayrefs (row-major).
## Numeric configuration
- set\_tolerance($eps), get\_tolerance()
Set/get the floating-point equality tolerance (default 1e-9).
- set\_units($units)
Store a units tag (e.g. `'mm'`); no automatic scaling is applied.
- set\_coordinate\_convention(handedness => ..., euler\_order => ...)
Store convention tags for downstream use.
## Mesh representation
All solid primitives that return a mesh use the structure:
{ verts => \@v, faces => \@f }
where `@v` is an array of `[$x,$y,$z]` position arrayrefs and `@f` is
an array of `[$i0,$i1,$i2]` triangle index arrayrefs. Winding order is
counter-clockwise when viewed from the outside (right-hand normal pointing
outward).
# ANAMORPHIC METHODS
An _anamorphic image_ is a distorted drawing which, when viewed from a
specific vantage point via a curved mirror, appears undistorted. The
methods in this section implement the cylindrical convex mirror variant.
The caller first builds a segment path using any drawing primitives (including
`importsvg`), then calls `anamorphic` to replace that path with its
distorted counterpart such that an observer at the configured viewpoint sees
the original image when looking at the mirror.
See [Graphics::Penplotter::GcodeXY::Anamorphic](https://metacpan.org/pod/Graphics%3A%3APenplotter%3A%3AGcodeXY%3A%3AAnamorphic) for the full description
of the physical model and image coordinate convention.
- anamorphic($cx, $cy, $R \[, %opts\])
Replace the current segment path with its anamorphic distortion for a
cylindrical mirror of radius `$R` centred at `($cx, $cy)`, then flush the
path via `stroke`.
The intended image is whatever is already in the segment path when this method
is called. The bounding box of the existing drawable segment endpoints is
used as the image extent. Each endpoint is independently projected onto the
paper via the cylindrical mirror model; segments whose endpoints cannot be
projected are dropped, and path continuity is maintained automatically.
The `$cx`, `$cy`, `$R`, and observer parameters must be expressed in the
same coordinate space as the segment path (device coordinates as used
internally by GcodeXY). For typical plots with no active transform this is
equivalent to the drawing unit.
Options:
- `obs_dist` (default 5\*R)
Horizontal distance from the observer to the cylinder axis. Must exceed `$R`.
- `obs_height` (default 5\*R)
Height of the observer's eye above the paper.
- `obs_angle` (default 0)
Azimuthal viewing direction in degrees. 0 = observer stands to the right of
the mirror (+x direction); 90 = from the top (+y), etc.
- `angle_range` (default: 90% of visible cone)
Total horizontal angular span of the image in degrees.
- `elev_range` (default: 80% of base elevation)
Total vertical angular span of the image in degrees.
- `step` (default 1.0)
Maximum distance (in drawing units) between consecutive sample points along
a segment. Smaller values give smoother distorted curves at the cost of
more output moves.
# SWIRL METHODS
A _swirl_ (also called _pursuit-curve polygon_) is produced by iteratively
constructing a series of nested polygons where each new vertex lies a fixed
fractional distance along an edge of the enclosing polygon. The corners of
successive polygons trace discrete approximations to logarithmic spirals.
The role is composed automatically when [Graphics::Penplotter::GcodeXY](https://metacpan.org/pod/Graphics%3A%3APenplotter%3A%3AGcodeXY) is
loaded; no extra `use` statement is required in user code.
See [Graphics::Penplotter::GcodeXY::Swirl](https://metacpan.org/pod/Graphics%3A%3APenplotter%3A%3AGcodeXY%3A%3ASwirl) for the construction algorithm
and termination conditions.
- swirl(%args)
Draw a whirl from the given polygon. Named arguments:
- `points => \@pts` (**compulsory**)
A reference to a flat array of vertex coordinates in alternating X, Y order:
`[x0,y0, x1,y1, ...]`. At least 3 vertices are required. Coordinates are
in the current drawing units.
- `d => \@d` (**compulsory**)
( run in 1.064 second using v1.01-cache-2.11-cpan-524268b4103 )