2017-05-03 44 views
1

MWE下面移動補丁的「錨點」在Matlab衝浪地塊

我密謀使用Matlabs surf功能的能量面。我首先在不同的方位角和仰角處創建數據點,然後使用通常的球面到笛卡爾方程將它們轉換爲(x,y,z)座標,並將座標轉換爲矩陣。但是,當我繪製這個圖時,我發現所有數據點都表示爲顏色「補丁」的左下角,而不是顏色補丁的中心。然而,當我縮放表面的半徑以反映該點處的能量時,表面中的任何凹痕由於這種效果而具有所有雜亂的顏色,即在可視化中任何對稱的數據都會丟失。 I would like this dimple to have roughly symmetrical color around the deepest point here.

顯示的示例是從球面座標向笛卡爾座標轉換爲兩個數據點之間的角度差的一半 - 這意味着補丁圍繞右側點着色,但着色仍然關閉。

有沒有辦法將數據的確切方向上的彩色斑點「居中」?

scaling = 100; 
min_val = 0.5 

count = 1; 
azstep = 10; 
elstep = 10; 

az = 0:azstep:360; 
el = -90:elstep:90; 
for ii = 1:length(az) 
    for jj = 1:length(el) 
     if any(az(ii) == [260 270 280]) && any(el(jj) == [-10 0 10]) 
      r_output(count) = 0.8; 
     else 
      r_output(count) = 1; 
     end 
     c(count) = r_output(count); 
     r(count) = 1 + scaling.*(r_output(count)/min_val) - scaling; 
     x(count) = (r(count)) .* cosd(el(jj)) .* cosd(az(ii)); 
     y(count) = (r(count)) .* cosd(el(jj)) .* sind(az(ii)); 
     z(count) = (r(count)) .* sind(el(jj)); 
     count = count + 1; 
    end 
end 

X = reshape(x,length(el),length(az)); 
Y = reshape(y,length(el),length(az)); 
Z = reshape(z,length(el),length(az)); 
C = reshape(c,length(el),length(az)); 

figure 
hold on 

surf(X,Y,Z,C) 
colorbar 
axis equal 
xlabel('X axis'); ylabel('Y axis'); zlabel('Z axis'); 

Result from code above

回答

0

更改陰影!

在你的代碼的末尾添加shading interp產生以下圖片:

enter image description here

,如果你想要的線條,然後更改衝浪呼籲:

h=surf(X,Y,Z,C) 
colorbar 
shading interp 
set(h','edgecolor','k') 

shading將刪除他們。

enter image description here

請注意,您仍然得到一些文物在一些彎道。它們似乎是在插值時由浮點錯誤產生的,所以改進它們的唯一方法似乎只是製造更加密集的球體。

+0

我曾嘗試'陰影interp'選項,應該已經寫了,但仍然不完全滿意的結果。但是,謝謝你的回覆!可能必須增加數據點的數量... –