cartesian_to_xy: Convert canvas coordinates to the data coordinates

Description Usage Arguments Details Value Examples

View source: R/transform.R

Description

Convert canvas coordinates to the data coordinates

Usage

1
cartesian_to_xy(x, y, track_index = current_track_index())

Arguments

x

X-locations of the data points in canvas coordinates.

y

Y-locations of the data points in canvas coordinates.

track_index

Index of the track.

Details

The data points are assigned to the nearest inner loops. Denote the a data point has a coordinate (r, theta) in the polar coordinate system, r_k and r_k+1 are the radius of the two loops at theta + 2*pi*a and theta + 2*pi*(a+1) that below and above the data point, the data point is assigned to the loop k.

Value

A data frame with two columns: x and y.

Examples

1
2
3
4
5
6
7
8
9
x = runif(100, -5, 5)
y = runif(100, -5, 5)
spiral_initialize()
spiral_track()
df = cartesian_to_xy(x, y)
# directly draw in the viewport
grid.points(x, y, default.units="native")
# check whether the converted xy are correct (should overlap to the previous points)
spiral_points(df$x, df$y, pch = 16)

spiralize documentation built on Feb. 6, 2022, 1:06 a.m.