Bland.Polar (Elixir Technical Drawing v0.4.0)

Copy Markdown View Source

Polar coordinate projection and helpers.

Cardioid and |cos 3θ| on polar axes

When a figure has projection: :polar, series data is interpreted as {θ, r} pairs where θ is in radians and r is the radius from the origin. The renderer projects each point through (θ, r) → (r·cos θ, r·sin θ) before applying the usual x/y scales.

The convention matches Matplotlib / Wolfram / most scientific plotting libraries: θ = 0 is on the positive x-axis (3 o'clock), and angles increase counterclockwise.

Prefer Bland.polar_figure/1 + Bland.polar_grid/2 over building this up by hand — they wire together the projection, a circular clip, and the concentric / radial reference grid in one shot.

Examples

iex> {x, y} = Bland.Polar.project({0.0, 1.0})
iex> {Float.round(x, 6), Float.round(y, 6)}
{1.0, 0.0}

iex> {x, y} = Bland.Polar.project({:math.pi() / 2, 2.0})
iex> {Float.round(x, 6), Float.round(y, 6)}
{0.0, 2.0}

Summary

Functions

Produces {thetas, rs} tracing a full circle of radius r — useful for drawing concentric reference rings on a polar plot.

Inverse of project/1: Cartesian → {θ, r}.

Project {θ, r} (polar, θ in radians) to {x, y} (Cartesian).

Functions

circle(r, n \\ 120)

@spec circle(number(), pos_integer()) :: {[float()], [float()]}

Produces {thetas, rs} tracing a full circle of radius r — useful for drawing concentric reference rings on a polar plot.

from_xy(arg)

@spec from_xy({number(), number()}) :: {float(), float()}

Inverse of project/1: Cartesian → {θ, r}.

project(arg)

@spec project({number(), number()}) :: {float(), float()}

Project {θ, r} (polar, θ in radians) to {x, y} (Cartesian).