Diana
Diana

Reputation: 102

create circles on a spline

I need a little information regarding creation of elements in the form of either circles or Hexagon along the entire spline as shown in below image in Matlab. Can you tell me how can i implement this in my code.

enter image description here

Please find the below code with respect to spline creation

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),'-');

Please let me know incase any additional information is required

Upvotes: 2

Views: 161

Answers (1)

Benoit_11
Benoit_11

Reputation: 13945

Well since you already know the locations at which you want to plot the circles (the [x,y] array) you can replicate part of the plot code you used but this time use larger markers and a different color:

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

which looks like this: enter image description here

You can use the 'hexagram' marker as well (i.e. use h instead of o) to get an hexagon:

enter image description here

Or if you want each circle to look different or control their properties individually you can also plot a rectangle with a curvature of [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

Upvotes: 1

Related Questions