在3d图上绘制水平线(2个圆周)

时间:2013-10-26 08:17:04

标签: r 3d plot plotrix

我试图将尺寸为xy的两个圆周与3d绘图一起绘制,并将两个圆的交点颜色绘制成颜色,我该怎么做?

# objective function
x <- seq(-1,1,.1)
y <- seq(-1,1,.1)
z <- x^2 + y^2

library(scatterplot3d)
library(plotrix)
scatterplot3d(x,y,z,pch=19,color="royalblue4")
draw.circle (1,1,1)
draw.circle (1,-1,1)

1 个答案:

答案 0 :(得分:1)

我不是真的在数学方面,但我会发布答案,因为它可能有用,而且,对于评论来说太大了。不过,如果我发布废话,请原谅我的无知。

#your data
library(scatterplot3d)
x <- seq(-1,1,.1)
y <- seq(-1,1,.1)
z <- x^2 + y^2

ang = 60 #angle of the 3D plot. experiment with different values

#your 3D plot, with extended xx', yy' limits
sp3d <- scatterplot3d(x, y, z, pch=19, color="royalblue4", 
           xlim = c(-1, 3), ylim = c(-3, 3), angle = ang)

#to use parametric equations of circles
f <- seq(-2*pi, 2*pi, 0.1)

#circle1
sp3d$points(x = 1 + 1*cos(f), y = 1 + 1*sin(f), z = rep(0, length(f)), type = "l")
#circle2
sp3d$points(x = 1 + 1*cos(f), y = -1 + 1*sin(f), z = rep(0, length(f)), type = "l")

情节是:

sp3d