【问题标题】:Colouring a Cylinder in MATLAB using the density of points located on it使用位于其上的点的密度在 MATLAB 中为圆柱体着色
【发布时间】:2014-08-16 18:09:47
【问题描述】:

我在 MATLAB 中有一个绘图,目前只是一个圆柱体。我还有大量来自该圆柱体上的实验的数据点。我想根据这些点的密度为圆柱体着色(即,深红色表示高密度,淡蓝色表示低密度)。我不确定最好的方法是什么。目前我分别为圆柱体绘制点和网格。这些点的间距不均匀。

rad = linspace( 0, 1, 100 )  ; 
theta = linspace( 0, 2 * pi, 100 ) ; 

[r, th] = meshgrid( rad, theta ) ; 

x = 190 * cos( th ) ; 
y = 115 * sin( th ) ;  

z = 1730 * r ; 

mesh( x, y, z ) 
hold on

x = [35.12 -44.44 24.98 -17.05 152.52 109.28 -181.85 -72.26 84.45 -89.96 55.02 70.88 172.08 -144.16 44.24 28.81 -30.14 72.79 -126.75 -37.22]

y = [-113.01 -111.80 -114.00 -114.53 -68.57 -94.07 -33.31 -106.35 -103.01 -101.28 -110.07 -106.69 -48.74 -74.90 -111.83 -113.66 -113.54 -106.22 -85.66 -112.71]

z = [1650.59 767.18 845.06 311.28 1352.75 921.70 1111.35 1572.80 1231.16 89.67 891.30 551.67 547.92 983.57 1746.61 1346.11 810.22 465.33 1564.76 1624.73]

scatter3( x, y, z )

下面是我想要实现的图形示例:

【问题讨论】:

  • 这是一个有趣的问题,但事实上,它的范围很广。请添加一些重要的代码和示例数据。
  • 考虑使用n维直方图:mathworks.com/matlabcentral/fileexchange/…
  • @natan,如果这些点位于圆柱面上,则应用于圆柱坐标的二维直方图 (hist3) 就足够了。
  • @Tyler,你能提供你的数据集吗?问题中的数据集不大(足以进行密度估计),并且这些点似乎不位于​​圆柱面上...
  • @A.Donda,我无法提供整个数据集。我确实提供的点确实位于绘制的圆柱体的表面上。它没有相等的x和y轴,所以我认为我不能使用matlab提供的圆柱体对象。

标签: matlab colors plot


【解决方案1】:

这里有点棘手...

让我们从估计圆柱体表面上点的密度开始,将它们的 3D 坐标转换为 2D(因为它们位于 3D 空间中的 2D 表面上)

xx = [35.12 -44.44 24.98 -17.05 152.52 109.28 -181.85 -72.26 84.45 -89.96 55.02 70.88 172.08 -144.16 44.24 28.81 -30.14 72.79 -126.75 -37.22];
yy = [-113.01 -111.80 -114.00 -114.53 -68.57 -94.07 -33.31 -106.35 -103.01 -101.28 -110.07 -106.69 -48.74 -74.90 -111.83 -113.66 -113.54 -106.22 -85.66 -112.71];
zz = [1650.59 767.18 845.06 311.28 1352.75 921.70 1111.35 1572.80 1231.16 89.67 891.30 551.67 547.92 983.57 1746.61 1346.11 810.22 465.33 1564.76 1624.73];

tt = atan2( yy./115, xx./190 ); %// angle in range [-pi pi]
tt( tt<0 ) = tt( tt<0 ) + 2*pi; %// in range [0..2*pi] for compatibility with definition of `theta`.
%//compute density using hist3
[n c] = hist3( [tt;zz]' ); %'// you can play with the granularity here...

在整个绘图表面上外推直方图

d = interpn( c{1}, c{2}, n, th, z, 'linear', 0 ); 

现在我们可以使用密度为圆柱体着色

mesh( x, y, z, d );

结果为

【讨论】:

  • 完全正确的方法恕我直言——除了外推,我会在调用 hist3 时指定 bin 边缘,以便它们覆盖整个区间 [0, 2pi]。
  • @A.Donda 谢谢。正如我在代码中评论的那样,hist3 是调整表示的粒度和准确性的地方。我在这里只提出了一个大纲......但你说得对,外推是需要注意和仔细规划的东西。
猜你喜欢
  • 2014-01-14
  • 2015-10-10
  • 1970-01-01
  • 2015-07-01
  • 2018-01-07
  • 1970-01-01
  • 1970-01-01
  • 2021-06-16
  • 1970-01-01
相关资源
最近更新 更多