Generate inner values of y for each x based on n
1 次查看(过去 30 天)
显示 更早的评论
I have the following code:
clear all
clc
n = 4; % number of divisions on the boundary
x1 = linspace(0,2,n);
y1_x1 = sqrt(1-( (x1.^2)/4 ) );
y2_x1 = -sqrt(1-( (x1.^2)/4 ) );
x2 = linspace(-2,0,n);
y1_x2 = sqrt(1-( (x2.^2)/4 ) );
y2_x2 = -sqrt(1-( (x2.^2)/4 ) );
x = [x1 x1 x2 x2];
y = [y1_x1 y2_x1 y1_x2 y2_x2];
scatter(x,y)
Now, is there a way to generate the inner values of y with respect to x?
For example, as we can see in the plot, an ellipse is formed, but the points are on the boundaries, I want points within the ellipse as well, such that it uses the values of x and y already calculated and connects the y values to x like at x = 0, y = 1.0000,0.9428,0.7454,0 and at next x on both positive and negative side (x = +-0.6667), y = 0.9428,0.7454,0 so on and so forth till x = +-2
But most importantly, it all stays connected, so that all I change is the value of n and the inner points are generated.
Thanks
0 个评论
采纳的回答
KSSV
2022-11-25
clc; clear all ;
clear all
clc
n = 4; % number of divisions on the boundary
x1 = linspace(0,2,n);
y1_x1 = sqrt(1-( (x1.^2)/4 ) );
y2_x1 = -sqrt(1-( (x1.^2)/4 ) );
x2 = linspace(-2,0,n);
y1_x2 = sqrt(1-( (x2.^2)/4 ) );
y2_x2 = -sqrt(1-( (x2.^2)/4 ) );
x = [x1 x1 x2 x2];
y = [y1_x1 y2_x1 y1_x2 y2_x2];
scatter(x,y)
% Arrange ellipe points properly
xCenter = mean(x);
yCenter = mean(y);
angles = atan2d(y - yCenter, x - xCenter);
[sortedAngles, sortOrder] = sort(angles);
x = x(sortOrder);
y = y(sortOrder);
[X,Y] = meshgrid(linspace(min(x),max(x)),linspace(min(y),max(y))) ;
Z = zeros(size(X)) ;
idx = inpolygon(X,Y,x,y) ;
Z(idx) = 1 ;
pcolor(X,Y,Z)
4 个评论
Saim
2022-11-25
Thanks a lot for the clarification
Is it possible to use the values of X and Y that you generated in a delaunay connection?
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spatial Search 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!