0

I'm using plotrix in R to draw NBA court features for plotting basketball shots. I'm having trouble getting the arc of the 3pt line exactly the way I want it. Using draw.arc and draw.circle allows the top of the arc to float. The top of the arc should always be at 29ft. draw.ellipse seems to solve this problem. However, when I segment the ellipse it leaves a "cross line" through the middle of the court depiction that I'd like to remove. However, I must segment the ellipse or it will extend past where it needs to. Any ideas?

Code used:

setwd("~")
library("plotrix", lib.loc="~/R/win-library/3.1")
library("RColorBrewer", lib.loc="~/R/win-library/3.1")
korver <- read.csv("Korver_XY_Test.csv", header = TRUE)
x <- (korver$x)
y <- (korver$y)
plot(x,y, cex=.7, col=brewer.pal(3, "Greens"))
#Draw 3pt Line
segments(3,0,3,14.19777, lwd=3)
segments(47,0,47,14.19777, lwd=3)
draw.ellipse(x=25, y=5.25, deg=TRUE, angle=0, arc.only= TRUE, segment=rbind(c(22,0),c(158,360)), a=23.75, b=23.75,  border=1, nv=200, lwd=3)
#Draw Half Court Line
segments(0,47,50,47, lwd=4)
#Draw Court Boundaries
abline(v=0, lwd=5)
abline(v=50, lwd=5)
abline(h=94, lwd=5)
abline(h=0, lwd =5)
#draw lane
segments(17,0,17,19, lwd=3)
segments(33,0,33,19, lwd=3)
segments(19,0,19,19, lwd=3)
segments(31,0,31,19, lwd=3)
segments(17,19,33,19, lwd=3)
draw.circle(25,19,6,100,lwd=3)
#draw hoop
draw.circle(25,5.25, 0.75, 200, lwd=2)
#draw backboard
segments(22,4,28,4, lwd=4)
Luke55122
  • 1
  • 2
  • 1
    Please make your code reproducible. You should include at the beginning `library("plotrix"); plot.new()`. However, when I add those steps, your code doesn't draw anything so I suspect there are other steps omitted. – Bryan Hanson Mar 24 '15 at 02:05
  • We don't have "Korver" so your example is not reproducible. Here is a minimal example: `plot(x = 1:50, y = 1:50, type = "n"); draw.ellipse(x=25, y=5.25, deg=TRUE, angle=0, arc.only= TRUE, segment=rbind(c(22,0),c(158,360)), a=23.75, b=23.75, border=1, nv=200, lwd=3)` Please clarify: you don't want the line that joins the ends of the arc? Using `draw.ellipse` that isn't possible, as it relies on `polygon` under the hood and that function always joins the ends. Please confirm, there is an alternative. – Bryan Hanson Mar 24 '15 at 11:13
  • That partially answers my question. Is there a way to draw this curve without using draw.ellipse? I can't make my data file with thousands of points available for you to reproduce the plotted points that are "korver.". I'm merely looking for an alternative way to draw a 3pt arc without a connecting "crossbar." – Luke55122 Mar 24 '15 at 14:18
  • Your best bet is to use grid graphics, not base graphics. You will have to tinker a bit at the start to see how they work, but then you can really get exactly what you want with full control. `library("grid"); browseVignettes("grid")` and check out the intro and the basics of viewports. After you draw all the rectilinear pieces, you can use `grid.curve` to add your 3 pt line. – Bryan Hanson Mar 24 '15 at 14:21
  • I was able to successfully draw the curve I wanted. However, it still "floated" as I adjusted size in the viewing window. This was the same problem I was having with everything but draw.ellipse. The nature of draw.ellipse where it keeps the radius true'd up with the a and b radius parameters keeps the radius true at 23.75 through the whole ellipse. I may just be stuck with the crossbar on the court because I don't see another way. Thanks for the help anyway. – Luke55122 Mar 25 '15 at 06:52
  • If the line is not a piece of an ellipse, you could do it in base graphics using `xspline`, or in any graphics environment with many short line segments. The latter will not scale well unless you make the segments very short, but it should work. – Bryan Hanson Mar 25 '15 at 11:22
  • xspline worked really well. It also works for circles (just do the top and bottom separately). I ended up creating vectors for the x and y points in Excel (trig distance formula). – Luke55122 Mar 27 '15 at 22:59
  • Very good! Now you can get going on your bracket analysis ;-) – Bryan Hanson Mar 28 '15 at 01:52

0 Answers0