【问题标题】:How can I wrap data points around an object in Octave如何在 Octave 中围绕对象包装数据点
【发布时间】:2020-01-04 23:38:18
【问题描述】:

我正在尝试将信号包裹在双曲锥体周围(锥体看起来像这样 http://www.sectioaurea.com/sectioaurea/the_golden_angle.htm)我发现可以将数据包裹在圆柱体周围。

请参阅下面带有包裹数据的圆柱体。

%% // Generate sample data
x = linspace(0,10*pi) ;
y2 = cos(x) ;
y1 = 10*cos(x/10) ;
y = y1+y2 ; y = y-min(y) ;
figure, 
plot(x,y,'-o') ;

%% // Basic cylinder (just for background)
[Xc,Yc,Zc] = cylinder(1*ones(1,50),50);
Zc = Zc * max(y) ;
surf(Xc,Yc,Zc) ;
hold on 

%% // Fold the points around the cylinder
Number_of_turn = 2 ;
xrange = [min(x),max(x)] ;
xspan = xrange(2)-xrange(1) ;
xc = x / xspan * 2*pi * Number_of_turn ;

Xp = cos(xc) ;
Zp = y ;
Yp = sin(xc) ;

plot3(Xp,Yp,Zp,'-ok') ;

但我不知道如何让它围绕双曲锥体包裹数据(锥体看起来像这样 http://www.sectioaurea.com/sectioaurea/the_golden_angle.htm

我在 Ubuntu 18.04 64 位中使用 Octave 4.2.2

【问题讨论】:

  • 关于“包装”,这里似乎没有发生任何神奇的事情。它只是一个surf 对象和一个plot3 对象,绘制在同一个axes 对象上(通过hold on)。只要您有正确的方程式,您就可以使用相同的方法在这样的“双曲锥”surfobject 上以相同的方式绘制“包裹函数”plot3 对象。
  • @TasosPapastylianou 这就是问题所在。方程sectioaurea.com/sectioaurea/the_golden_angle.htm。问题始于cylinder 命令如何使用它制作双曲锥。

标签: arrays 3d octave hyperbolic-function


【解决方案1】:

这是一个例子

% plot surface
[X,Y] = ndgrid( -0.1:0.001:0.1, -0.1:0.001:0.1 );
Z = 1 ./ sqrt(X.^2 + Y.^2);   % The height at each X,Y grid point is
                              % the inverse of its norm

surf(X,Y,Z, 'edgecolor', 'none');
colormap cool
camlight

%plot spiral
Theta = [1:0.1:500];
Z = Theta;    % height increases same as angle
Norm = 1 ./ Z;   % the definition of the hyperbolic cone
X = cos(Theta) .* Norm;
Y = sin(Theta) .* Norm;

hold on
plot3(X,Y,Z, 'r', 'linewidth', 1.5 )
hold off

axis([-0.1, 0.1, -0.1, 0.1, 0, 500])

更新

这是另一个例子,包装一个特定的函数;希望它能证明你的想法。注意我必须稍微偏移高度,否则接近零高度的双曲锥非常接近无穷大,这很难绘制。

%% Generate a hyperbolic cone surface, and 'wrap' an arbitrary 1D function to it, by
%% treating the function's x-coordinate as an angle, and for each such
%% angle, projecting the corresponding height onto the surface of the cone at the same
%% height.

%%%%%%%%%%%%%%%%%%%%%%
% Generate sample data
%%%%%%%%%%%%%%%%%%%%%%

   x = linspace( 0, 10 * pi );   % Generate 100 points (default) from 0 to 10π
   h = cos(x) + 10 * cos( x / 10 );   h = h - min(h);
   h = 30 * h + 30;   % make it a bit taller, and small offset so that low values
                      % don't end up near infinity when mapped onto the hyperbolic
                      % cone surface

%%%%%%%%%%%%%%%%%%
% Generate Surface
%%%%%%%%%%%%%%%%%%

 % Generate a suitable XY grid
   [GridX, GridY] = ndgrid( -0.1:0.0005:0.1, -0.1:0.0005:0.1 );

 % For each point on the grid, calculate a distance Δ from the (0,0) origin.
   Delta = sqrt( GridX .^ 2  +  GridY .^ 2 );

 % According to the definition of the hyperbolic cone, the height Z at each gridpoint
 % is equal to 1 over Δ
   Z = 1 ./ Delta;

 % Plot the resulting surface with height Z at each gridpoint X,Y
   surf( GridX, GridY, Z, 'edgecolor', 'none' );

 % Give the surface a nicer appearance
   colormap( 'ocean' ); caxis([0, 25]); camlight;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Wrap data around generated surface
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

   NumberOfTurns = 2;
   XRange  = [ min( x ), max( x ) ];
   XSpan   = XRange(2) - XRange(1);
   XOffset = XRange(1)

 % Convert x inputs to angles Theta ('xc' in previous example code)
   Theta  = (NumberOfTurns * 2 * pi / XSpan) * (x - XOffset);

  % Since, according to the hyperbolic cone equation, 'H = 1 / Δ' (where H denotes
  % Height, and Δ denotes distance from the [0,0] origin), it follows that for a
  % given H, we can find the corresponding Δ as Δ = 1 / H. Therefore, for each
  % [θ, h] pair, we can find a distance Δ, such that the cartesian point
  % [ Δcos(θ), Δsin(θ), h ] sits on the cone. We use this fact to 'wrap' the
  % trajectory function around the cone.

  Delta = 1 ./ h;   % overwriting old Delta definition for notational convenience.

  WrappedX = Delta .* cos( Theta );
  WrappedY = Delta .* sin( Theta );
  WrappedZ = h;

 % Plot the wrapped datapoints over the previous surface graph
   hold on
   plot3( WrappedX, WrappedY, WrappedZ, '-or', 'linewidth', 1.5, 'markersize', 4, 'markerfacecolor', [0.5,0,0], 'markeredgecolor', [0.25,0,0]);
   hold off

 % Set appropriate axis limits to visualise relevant range
   axis([-0.1, 0.1, -0.1, 0.1, 0, 1000]);
   set(gca, 'color', [0.5,0.5,0.5]);

【讨论】:

  • Papastlianou 谢谢,但是当我尝试通过更改%% // Fold the points around the cylinder 中的部分来映射曲线周围的点时,它们不会像圆柱体示例中那样围绕对象“折叠”。任何想法为什么?
  • @RickT 大概与您更改部分的方式有关?
  • 圆柱体由一组方程控制,双曲锥体由另一组方程控制。汽缸在这里并不比可乐更重要。为什么您如此热衷于使用 cylinder 函数作为此问题的一部分?如果你有一个表面方程和一个轨迹函数方程,你的问题就解决了。你了解基本的双曲函数是如何产生锥面和这个螺旋轨迹的吗?
  • 很抱歉,如果有错过的通信。您如此友好地发布的代码让我过去了,我在我的代码中指的是标题为%% // Fold the points around cylindersection,该代码来自原始问题doesn't,在那里使用了圆柱体命令(至少该部分)。目前我已将其缩小到最后的 xc 变量。
  • 好的,我想我明白了误解的所在。您不只是想重新创建链接中显示的螺旋轨迹。你想要的是正弦轨迹。原理是一样的,但既然我明白了你在追求什么,我将用相关的cmets重写示例。
猜你喜欢
  • 1970-01-01
  • 2015-05-31
  • 2010-11-09
  • 1970-01-01
  • 2019-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-10
相关资源
最近更新 更多