Generate inner values of y for each x based on n
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
KSSV
on 25 Nov 2022
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 Comments
Saim
on 25 Nov 2022
Thanks a lot for the clarification
Is it possible to use the values of X and Y that you generated in a delaunay connection?
More Answers (0)
See Also
Categories
Find more on Spatial Search in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!