在样条曲线上创建圆

时间:2017-04-04 10:13:40

标签: matlab spline

我需要一些关于沿着整个样条曲线以圆形或六边形形式创建元素的信息,如下图中的Matlab所示。你能告诉我如何在我的代码中实现这一点。

enter image description here

请参阅以下有关样条线创建的代码

x = -4:4;
y = [0 .15 1.12 2.36 2.36 1.46 .49 .06 0];
cs = spline(x,[0 y 0]);
xx = linspace(-4,4,101);
plot(x,y,'o',xx,ppval(cs,xx),'-');

如果需要任何其他信息,请告诉我

1 个答案:

答案 0 :(得分:1)

好了,因为您已经知道要绘制圆圈的位置([x,y]数组),您可以复制您使用的plot代码的一部分,但这次使用更大的标记和不同的颜色:

hold on
plot(x,y,'o',xx,ppval(cs,xx),'-');
plot(x,y,'o','MarkerSize',80,'Color','g');

看起来像这样: enter image description here

你也可以使用'hexagram'标记(即使用h代替o)来获得六边形:

enter image description here

或者,如果您希望每个圆圈看起来不同或单独控制其属性,您还可以绘制曲率为[1 1]的矩形:

radius = .5; 

for k = 1:numel(x)
centerX = x(k);
centerY = y(k);
rectangle('Position',[centerX - radius, centerY - radius, radius*2, radius*2],...
    'Curvature',[1 1],...
    'EdgeColor','g','FaceColor','none');
end