File: draw.radial.line.R

package info (click to toggle)
r-cran-plotrix 3.8-1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,580 kB
  • sloc: makefile: 6
file content (32 lines) | stat: -rw-r--r-- 1,045 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
draw.radial.line <- function(start, end, center=c(0, 0), angle=0, deg=NA, expand=FALSE,
    col=NA, lwd=NA, ...) 
    {
    if (is.na(col))
        col <- par("col")
    if (is.na(lwd))
        lwd <- par("lwd")
    if (is.na(deg))
        deg <- angle*180/pi
    angle <- deg*pi/180
    cosang <- cos(angle)
    sinang <- sin(angle)
    xylim <- par("usr")
    plotdim <- par("pin")
    ymult <- (xylim[4] - xylim[3])/(xylim[2] - xylim[1]) * plotdim[1]/plotdim[2]
    if (!expand || end <= 0)
        {
        px <- c(start, end)
        lines(center[1]+px*cosang, center[2]+px*sinang*ymult, col=col, lwd=lwd, ...)
        }
    else
        {
        devunits <- dev.size("px")
        lwdend <- (lwd/2)*(xylim[2]-xylim[1])/devunits[1]
        px <- c(start, start, end, end)
        lwdstart <- lwdend * start/end
        py <- c(lwdstart, -lwdstart, -lwdend, lwdend)
        pxt <- center[1] + px*cosang - py*sinang*ymult
        pyt <- center[2] + px*sinang + py*cosang*ymult
        polygon(pxt, pyt, border=col, col=col)
        }
    }