So I have a function of a figure, and I am trying to generate at least a hundred points inside the figure. I have no problem generating the points itself but I can't seem to make them stay within the figure, some of the points go out of the figure which is not what I intended
clear; close all; clc;%heart
[X,Y,Z]=meshgrid(-1.5:0.03:1.5);F=(((X.^2) + (9/4).*(Y.^2) + Z.^2-1).^3+(-X.^2 .* Z.^3 -(9/80).*Y.^2.*Z.^3));%function defining a heart
patch(isosurface(X, Y, Z, F, 0), 'FaceColor', 'w', 'FaceAlpha',.3,'EdgeAlpha',.1);view(3)xlabel('x');ylabel('y');zlabel('z');axis equal;grid on;%
hold on; %random points
x = -1 + (1+1)*rand(1,100); %x-coordinate of a point
y = -0.6 + (0.6+0.6)*rand(1,100); %y-coordinate of a point
z = -0.8 + (1.2+0.8)*rand(1,100); %z-coordinate of a point
scatter3(x, y, z, 'MarkerFaceColor','b','MarkerEdgeColor','b');hold off
Best Answer