Skip to content

Instantly share code, notes, and snippets.

@Robinlovelace
Created May 11, 2015 15:53
Show Gist options
  • Save Robinlovelace/609227d083357408fbda to your computer and use it in GitHub Desktop.
Save Robinlovelace/609227d083357408fbda to your computer and use it in GitHub Desktop.
A plotting method for the example 'bike' class
library(plotrix)
plot.bike <- function(x, ...){
centre_back <- c(0, x$ws / 2)
centre_front <- c(x$ws + x$ttl + 100, x$ws / 2)
xlim <- c(-x$ws, centre_front[1] + x$ws / 2)
ylim <- c(0, x$ttl + x$ws/2 + 50)
plot.new()
plot.window(xlim, ylim)
draw.circle(x = centre_back[1], y = centre_back[2], radius = x$ws/2)
draw.circle(x = centre_front[1], y = centre_back[2], radius = x$ws/2)
ttx <- c(0, x$ttl) + x$ws/2 + 100
tty <- rep(x$ws / 2 + x$s, 2)
stx <- rep(x$ws/2 + 100, 2)
sty <- c(0, x$s) + x$ws/2
lines(ttx, tty)
lines(stx, sty)
lines(c(0, ttx[1]), c(sty[1], sty[2]))
lines(c(0, ttx[1]), c(sty[1], sty[1]))
lines(c(ttx[1], ttx[2]), c(sty[1], sty[2]))
lines(c(centre_front[1], ttx[2]), c(sty[1], sty[2]))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment