Skip to content

Instantly share code, notes, and snippets.

@Akiyah
Created December 11, 2017 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akiyah/15d3632c05132f9c8b900f39bf0e1f62 to your computer and use it in GitHub Desktop.
Save Akiyah/15d3632c05132f9c8b900f39bf0e1f62 to your computer and use it in GitHub Desktop.
outer_product <- function (a, b) {
c(a[2]*b[3] - a[3]*b[2], a[3]*b[1] - a[1]*b[3], a[1]*b[2] - a[2]*b[1])
}
d <- function(t) {
s <- t/sqrt(3)
h <- sqrt(1 - ((1 + sqrt(3)/2)^2 + (1/2)^2)*s^2)
A <- c(s, 0, 0)
B <- c(-1/2*s, sqrt(3)/2*s, 0)
A_ <- c(-sqrt(3)/2*s, 1/2*s, h)
B_ <- c(0, -s, h)
AA_ <- A_ - A
BB_ <- B_ - B
BA <- A - B
AA_xBB_ <- outer_product(AA_, BB_)
((A - B) %*% AA_xBB_) / sqrt(AA_xBB_ %*% AA_xBB_)
}
ts <- (1:89)/100
ds <- c()
for (i in 1:89) {
ds[i] <- d(ts[i])
}
plot(ts, ds, type="l")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment