Code Monkey home page Code Monkey logo

dddr's Introduction

dddr: Three-Dimensional Vector Operations in R

About

The R package dddr is a vctrs-based package for working with three-diensional spatial data. It gives three-dimensional objects like points, velocities, and rotations first-class vector status in R, enabling usage as column types within data.frame and tibble.

In contrast to most spatial R packages like sf or rspatial that work with geographic, 2-dimensional data, dddr works best with 3-dimensional data. The origin of this package was to analyze behavioral data (e.g, hand motion, head direction) in studies of virtual and augmented reality.

R-CMD-check Codecov test coverage

Quick View

library(tidyverse)
library(dddr)
spiral <- tibble(i = seq(0, 10*pi, 0.05)) %>%
  mutate(
    # vector3s are created using three numeric vector arguments,
    # and thanks to dplyr, can refer to other columns in the dataframe
    circular_part = vector3(x=cos(i), y=sin(i), z=0),
    forward_part = vector3(x=0, y=0, z=i/15),
    # vector3s can be added together and multiplied by numerics 
    spiral_part = circular_part * i / 30 + forward_part
  )

spiral %>% head(10)
## # A tibble: 10 x 4
##        i      circular_part    forward_part                   spiral_part
##    <dbl>             <vct3>          <vct3>                        <vct3>
##  1  0    (1    , 0     , 0) (0, 0, 0      ) (0      , 0        , 0      )
##  2  0.05 (0.999, 0.0500, 0) (0, 0, 0.00333) (0.00166, 0.0000833, 0.00333)
##  3  0.1  (0.995, 0.0998, 0) (0, 0, 0.00667) (0.00332, 0.000333 , 0.00667)
##  4  0.15 (0.989, 0.149 , 0) (0, 0, 0.01   ) (0.00494, 0.000747 , 0.01   )
##  5  0.2  (0.980, 0.199 , 0) (0, 0, 0.0133 ) (0.00653, 0.00132  , 0.0133 )
##  6  0.25 (0.969, 0.247 , 0) (0, 0, 0.0167 ) (0.00807, 0.00206  , 0.0167 )
##  7  0.3  (0.955, 0.296 , 0) (0, 0, 0.02   ) (0.00955, 0.00296  , 0.02   )
##  8  0.35 (0.939, 0.343 , 0) (0, 0, 0.0233 ) (0.0110 , 0.00400  , 0.0233 )
##  9  0.4  (0.921, 0.389 , 0) (0, 0, 0.0267 ) (0.0123 , 0.00519  , 0.0267 )
## 10  0.45 (0.900, 0.435 , 0) (0, 0, 0.03   ) (0.0135 , 0.00652  , 0.03   )
spiral %>%
  # field access uses the $ operator
  ggplot(aes(vector3=spiral_part)) +
  stat_point3(geom="point") +
  #geom_path3() +
  coord_look_at_front()

spiral %>%
  mutate(
    # rotations can be specified using quaternions, axis / angle, or even from / to vectors
    spiral_rotated = rotate(spiral_part, axis=vector3(0, 1, 0), angle=pi/4)
  ) %>% 
  ggplot(aes(x=spiral_rotated$x, y=spiral_rotated$y)) +
  geom_point() +
  geom_path() +
  coord_equal()

Plotting

simple_dddr_plot <- function() {
  spiral <- tibble(i = seq(0, 10*pi, 0.05)) %>%
    mutate(
      circular_part = vector3(x=cos(i), y=sin(i), z=i/15),
      forward_part = vector3(x=0, y=0, z=i/15),
      spiral_part = circular_part * i / 30 + forward_part
    )

  spiral %>%
    ggplot() +
    stat_point3(aes(vector3=spiral_part)) +
    coord_look_at_front()
}

Installation

install.packages("devtools") # if you have not installed "devtools" package
# For the most recent packaged & released version
devtools::install_github("MrMallIronmaker/dddr@*release")
# For the development version
devtools::install_github("MrMallIronmaker/dddr")

Questions

If you have questions in how to use this library, what this library is useful for, or if it has any particular features, it would be helpful to contact me directly at mrmillr at stanford.edu. This project is in its early development stages, and I want to know how you want to use the library / are using the library.

Contributions

Contributions are welcome! The issue tracker in this repo can be used for bug reports, feature requests, and questions - whatever you might need.

dddr's People

Contributors

markromanmiller avatar rjc45 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

alee8599

dddr's Issues

Consider a lintr for switch statement blanks

Right now, in both the ops files, there's a handful of # nolint comments that ignore warnings with equals / commas in switch statements. The linter should be modified to allow that.

Quaternion creation API

With rotate, shouldn't it be possible to create quats in all those sensible ways? Maybe something like "quaternion_from_rotation(...)" with all the args in rotation?

De-risk plotting interface tech

The most natural way (to me) to set up the interface is to create a new geom representing points (geom_vector3, geom_vector3_spoke) and have coords represent the particular view (coords_look_at_bottom, coords_looking_down)

create hex sticker!

For fun.

I'm picturing a vector with a rotation arrow with three lines, each label with a "D" and the vector itself labeled with an "R" - but somehow readable.

Consider benchmarking?

I'm sure I'll run into slower code once I start loading real datasets. I wonder how Hale's data will do.

Terminology regarding collations

Right now there are a handful of class names and I should keep them all straight.

eval is ambiguous between 'evaluated' (adj) and 'evaluate' (v). It's used more often in the tidyverse as the verb (e.g, eval_tidy) so I'd like to refactor to make that clear.

Rename vrmvrm to something else

vrmvrm is similar to vroom from the tidyverse, and the full name (VectoR Manager for Virtual Reality and Motion) is too focused on VR.

  • dddr
    • Short, memorable, and easily associated with what it does (3D R)
    • Maybe collides with DDD (data-driven documents? domain-driven design)
  • thredr
    • Nice -r
    • Too similar to knitr?
  • threedr
    • Weird pronunciation
  • "three-dimensional spatial data"
    • threds - collides with "threads" the computing object
    • tdsd
  • threedeer
    • a lot of collisions with "three deer" the phrase
  • r3d
    • a lot of collisions with other things (companies, other libraries)
  • Sutherland: VR being a "mathematical wonderland"
    • wondr
    • wondrland
    • suthr
    • suthrland
  • comequat
    • vectors = come and quat = quaternion? and a pun on kumquat?
  • plays on the world "vector"
    • rotvec
    • vecrot
    • rotcev
  • spacer
    • too similar to spacing things out?
  • spatial
    • might be too similar to rspatial

Settings vignette

Why do we need settings (how are conventions different)?

What objects are covered in settings?

(e.g, A handful of ways to create Euler angles)

Change of Basis functions?

Oftentimes we don't want to actually be rotating and/or translating points, but rather reinterpret them according to some basis. How can that basis be defined? How can it be defined clearly?

Quaternions vignette?

Reading them (axis-half-angle interpretation)

https://stackoverflow.com/questions/34946219/linking-r-package-vignettes

A solid physical interpretation of quaternions (about an hour or so)
https://youtu.be/d4EgbgTm0Bg
https://youtu.be/zjMuIxRvygQ
https://eater.net/quaternions

A few points to interpolate between:

Identity: (1;0,0,0)
Double cover = negative everything is the same.
Conjugate = negative xyz is opposite operation

180 around x
0,1,0,0

90 around x
0.707, 0.707, 0, 0

Implementation of dot and cross in vector

  • Tests for dot
  • Implementation of dot
  • Tests for cross
  • Implementation of cross
  • When two vectors are multiplied, add a special error detail asking if they want dot or cross

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.