I am trying to get the XData and YData on a contourslice in matlab. I want this contourline to be on a patch that I have already made in 3D. The patch corresponds to a rectangular plane orthogonal to the -x axis rotated about the y axis from -x by some angle dphi. I have provided some of my code below with images.
AoAd = 45;
Ty = 1/2*cosd(AoAd); % wing position in y
Tz = 1/2*sind(AoAd); % wing position in z
yslice = [Ty, Ty, -Ty, -Ty]+[1/2, 1/2, -1/2, -1/2];
zslice = [-Tz, Tz, Tz, -Tz]+[-1/2, 1/2, 1/2, -1/2];
xslice = -.15;
S = [xslice*ones(size(yslice));
yslice;
zslice];
dphi = 7.5; % degrees
MR = [[cosd(dphi) 0 -sind(dphi) 0];...
[0 1 0 0];...
[sind(dphi) 0 cosd(dphi) 0];...
[0 0 0 1]];
S_prime = MR*[S,[0,0,0]';
[0,0,0,0],1];
x = S_prime(1,1:4);
y = S_prime(2,1:4);
z = S_prime(3,1:4);
figure
hold on
patch(x,y,z,'r')
cc = contourslice(Xw,Yw,Zw,D_ta,z,y,x,[-3,-3],'linear');
Now, I expect the there two be a single iso-line on the red patch. But instead I get several iso-lines that look orthogonal to the red patch. Can I get some help figuring out what I'm doing wrong here.
It seems to me that the smaller region is at least on a parallel plane but I don't know why the others aren't.
Addendum:
I also tried using the XYZ data from patch and this was the result. Still not on the plane, and there are some slices on different planes.
figure
hold on
p = patch(x,y,z,'r');
xp = p.XData;
yp = p.YData;
zp = p.ZData;
cc = contourslice(Xw,Yw,Zw,D_ta,xp,yp,zp,[-3,-3],'linear');

2 件のコメント

darova
darova 2019 年 8 月 3 日
Just to clarify: you want to project your data onto red plane?
Nathaniel H Werner
Nathaniel H Werner 2019 年 8 月 3 日
編集済み: Nathaniel H Werner 2019 年 8 月 3 日
Yes, I am trying to get a volume slice of the data on the red patch. If you can't run the code try using the built in flow or peaks.

サインインしてコメントする。

 採用された回答

darova
darova 2019 年 8 月 3 日

1 投票

Try to refine mesh of your plane
I attached a simple example (help example modified)
Can you attach your data

16 件のコメント

Nathaniel H Werner
Nathaniel H Werner 2019 年 8 月 3 日
Unfortunately I am unable to attach any of my data at this time. I can try on Monday when I get back to the office but the files might be too big.
This looks like it might work but I will verify if it does with my data on Monday.
darova
darova 2019 年 8 月 3 日
I will be waiting here
Nathaniel H Werner
Nathaniel H Werner 2019 年 8 月 3 日
Well it works, and it doesn't work. For the planes you made it works it just fine with any 3D data. But I need to use the rotated plane described something like this.
[ys,zs] = meshgrid(-2:0.2:2);
xs = -.1*ones(size(ys));
xv = xs(:)';
yv = ys(:)';
zv = zs(:)';
M = [cosd(angle) 0 -sind(angle) 0;...
0 1 0 0;
sind(angle) 0 cosd(angle) 0;
0 0 0 1];
v = M*[xv;
yv;
zv;
ones(size(xv))];
xs_prime = reshape(v(1,:),[21,21]);
ys_prime = reshape(v(2,:),[21,21]);
zs_prime = reshape(v(3,:),[21,21]);
You can see that if I make a patch with this data the contourslice is not on the rotated plane.
x = [max(xs_prime(:)) max(xs_prime(:)) min(xs_prime(:)) min(xs_prime(:))];
y = [max(ys_prime(:)) max(ys_prime(:)) min(ys_prime(:)) min(ys_prime(:))];
z = [min(zs_prime(:)) max(zs_prime(:)) max(zs_prime(:)) min(zs_prime(:))];
hold on
% mesh(xs,ys,zs)
h = patch(x,y,z,'r');
alpha(h,0.5)
hold off
view(3)
grid on
xlabel('X axis')
ylabel('Y axis')
axis equal
darova
darova 2019 年 8 月 4 日
Try surf() instead of patch() then:
h = surf(xs_prime,ys_prime,zs_prime,'EdgeColor','none','FaceColor','red');
alpha(h,0.5)
Nathaniel H Werner
Nathaniel H Werner 2019 年 8 月 5 日
It's a little hard to see, but I just incorporated that into the untitled code and it gave the same result. The red line is the surf, the blue is a part of flow.
Capture.PNG
darova
darova 2019 年 8 月 5 日
Can you please attach you data? Maybe i could try
Nathaniel H Werner
Nathaniel H Werner 2019 年 8 月 5 日
I just uploaded the four variables D_ta, Xw, Yw, and Zw.
darova
darova 2019 年 8 月 5 日
Here is what i achieved (like it very much)
img11.png
I attach the beautiful script also
Nathaniel H Werner
Nathaniel H Werner 2019 年 8 月 5 日
It looks good but my planes need to be rotated about the y-axis. I believe dphi = 7.5 deg if I haven't included that already in the original code I will. Could you see if your code is able to get the same results on a plane like that?
darova
darova 2019 年 8 月 5 日
xs = ys*tand(7.5);
imgg.png
Nathaniel H Werner
Nathaniel H Werner 2019 年 8 月 5 日
Looks great, I will check it out myself tonight and accept it if it works.
Nathaniel H Werner
Nathaniel H Werner 2019 年 8 月 6 日
For those that don't want to go searching through the comments for the code, here is what was attached.
clc,clear
cla
load Data_8519.mat
% create new plane
yw = linspace(-1,1,20);
zw = linspace(-5,5,20);
[ys,zs] = meshgrid(yw,zw);
xs = ys*0;
% lvls = linspace(min(D_ta(:)), max(D_ta(:)), 20);
k = 0;
hold on
for i = -4:2:4
k = k + 1;
h(k) = surf(xs+i,ys,zs);
contourslice(Xw,Yw,Zw,D_ta,xs+i,ys,zs,10)
end
alpha(h,0.5)
set(h,'EdgeColor','none','FaceColor','r');
hold off
view(3)
grid on
xlabel('X axis')
ylabel('Y axis')
zlabel('Z axis')
axis equal
Nathaniel H Werner
Nathaniel H Werner 2019 年 8 月 6 日
編集済み: Nathaniel H Werner 2019 年 8 月 6 日
I'm sorry I was mistaken when I previously accepted the answer.
There is some misunderstanding about how to rotate the plane.
Take this section of code.
yw = linspace(-5,5,50);
zw = linspace(-5,5,50);
figure
RoLoc = linspace(0.1:3,50)
for r=1:length(RoLoc)
R = [RoLoc(r)*ones(50,1),yw(:),zw(:),ones(50,1)]';
MR = [cosd(7.5) 0 -sind(7.5) 0;...
0 1 0 0;...
sind(7.5) 0 cosd(7.5) 0;
0 0 0 1];
R_prime = MR*R;
xw = R_prime(1,:);
zw = R_prime(3,:);
[xs,ys,zs] = meshgrid(xw,yw,zw);
hold on
surf(xs,ys,zs);
contourslice(Xw,Yw,Zw,D_ta,xs,ys,zs,[-3,-3])
end
What I need is for the contourslice to be on the plane xs, ys, zs. I am unable to create a surf with that 3D meshgrid data. Running the above code gives me this error.
Error using matlab.graphics.chart.primitive.Surface/set
Value must be a vector or 2D array of numeric type
Error in matlab.graphics.chart.internal.ctorHelper (line 8)
set(obj, pvpairs{:});
Error in matlab.graphics.chart.primitive.Surface
Error in surf (line 144)
hh = matlab.graphics.chart.primitive.Surface(allargs{:});
To summarize the process.
  1. The first plane should start parallel to the yz plane (normal aligned with -x).
  2. Rotate the plane about the y-axis by an angle dphi = 7.5 deg measured from the -x axis.
  3. Extract the rotated x, y, and z data.
  4. Make a contourslice on this new rotated surface.
If this is corrected I can accept the answer. I will continue trying to figure out why I am getting this error.
Additionally
If you run the portion of the code just with contourslice you get this error.
Error using contourc
Input arguments for contourc must have at most 2 dimensions.
Error in contourslice (line 239)
c = contourc(vi, cvals);
darova
darova 2019 年 8 月 6 日
Sorry, misunderstood you about rotation Y axis
img1.png
darova
darova 2019 年 8 月 6 日
Maybe you wanted slice of XZ plane? I like it more
img2.png img3.png
Nathaniel H Werner
Nathaniel H Werner 2019 年 8 月 6 日
The right image looks exactly like what I need, the red planes are XY or YZ planes rotated around the Y axis. Does the new Untitled3 script make that figure?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

製品

リリース

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by