基于方程在坐标系中寻找点

时间:2015-12-15 13:54:53

标签: r 3d coordinate-systems

我有许多不等式,我想将这些点转换为三维坐标系xyz

我需要找到满足所有不等式的所有可能点,保存每个点,然后将其绘制为3d散点图。

简化数据示例:

#Inequalities (I have several more)
df <- data.frame(
  x = c(0.5, 0.4, 0.1), 
  y = c(0.7, 0.11, -0.25), 
  z = c(-0.5, -0.02, 1),  
  v = c(90, 2500, 350))

# Limits of the coordinate system
x.lim <- seq(-100, 100, by = 1) 
y.lim <- seq(-100, 100, by = 1) 
z.lim <- seq(-50, 50, by = 1) 

# Basic check - must be true for all points: 
df$x + df$y + df$z < df$v

# Looping through all points of the coordinate system 
# no need to test row 2, # if the first row is false

df$x*-100 + df$y*-100 + df$z*-50 < df$v 
# if all conditions are true, save the point to a list/matrix to be able to plot it
df$x*-99 + df$y*-100 + df$z*-50 < df$v
#...
df$x*-100 + df$y*-99 + df$z*-50 < df$v
df$x*-99 + df$y*-98 + df$z*-50 < df$v
#...
df$x*100 + df$y*100 + df$z*50 < df$v

所以,最后我会得到一个矩阵m - 它包含所有真实变量的测试,看起来像这样:

m
x        y     z
-100   -100   -50
99     -100   -50
...
100     100    50

最后,我可以将所有TRUE-TRUE-TRUE结果绘制成三维散点图,例如:

plot3d(x = m[, 1], y = m[, 2], z = m[, 3], col = "blue", size = 4, 
       xlim = c(-100, 100), ylim = c(-100, 100), zlim = c(-50, 50))

我可能有更多的方程式和更大的坐标系,所以速度也是我正在研究的问题。我的主要问题是如何编写条件循环并查看所有可用的不同值,然后将正确的值保存到矩阵中。

0 个答案:

没有答案