Hai,
I am working on optics. I have plotted a lens in matlab. The rays of light emerging out of the lens, after undergoing refraction in the lens, needs to be projected on a square plane in front of the lens. How is it possible to draw a plane in matlab? Looking forward to hearing from you soon.
BSD

 채택된 답변

Walter Roberson
Walter Roberson 2011년 9월 21일

0 개 추천

You can use patch() to draw a shape embedded in 3D.

댓글 수: 7

bsd
bsd 2011년 9월 23일
I gave the command patch([0,0] [0,1] [1,1] [1,0]), it is showing an error "unbalanced or unexpected parenthesis or bracket". The above points are the coordinates of a square plane in 2D.
BSD
Fangjun Jiang
Fangjun Jiang 2011년 9월 23일
You forgot the comma.
patch([0,0], [0,1], [1,1], [1,0])
bsd
bsd 2011년 9월 23일
I added the comma, it is not showing error. But only a line from the point (0,0) to (0,1) is displayed, other lines of the square is not displayed.
BSD
Fangjun Jiang
Fangjun Jiang 2011년 9월 23일
See doc patch for examples.
Walter Roberson
Walter Roberson 2011년 9월 23일
All of the x data must be together, and all of the y data must be together.
patch([0 0 1 1 0], [0 1 1 0 0], [0 0 0 0 0])
Notice I have provided z coordinates here, to make it a 3D patch in order to make it a plane as was required by the original question. If all that is required is a 2D square then you could use rectangle() instead.
bsd
bsd 2011년 9월 24일
http://www.opticasoftware.com/documentation/Rayica/PrinciplesOfRayica/4Customization/index.html#.1.2
go to the above link, and see the figure just immediately above the section 4.3. This is what I want to do using matlab, after the rays emerge out of the lens, and they hit an aperture in front of it, as seen in the above figure.
Walter Roberson
Walter Roberson 2011년 9월 24일
Yup, you will be wanting non-zero z for that. The basic call will be as I gave above, patch([0 0 1 1 0], [0 1 1 0 0], [0 0 0 0 0]), but you will want different coordinates. The first parameter is a list of the x coordinates, the second parameter is a list of the corresponding y coordinates, and the third parameter is a list of the corresponding z coordinates.
You will also want to create a patch() for each of the apertures. You can use the usual sin() vs cos() coordinates if your square is perpendicular to one of the axes. For example,
sides = 17;
radius = 3;
angles = linspace(0,2*pi,sides+1) .';
coords = [radius * sin(angles), zeros(size(angles)), radius * cos(angles)];
xoff = 5; yoff = 2.8; zoff=3.3;
patch(xoff + coords(:,1), yoff + coords(:,2), zoff + coords(:,3));
and to draw the next circle, just change the xoff, yoff, zoff, and repeat the patch() command.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Sean de Wolski
Sean de Wolski 2011년 9월 21일

0 개 추천

You could also use a surf or a slice

댓글 수: 1

Walter Roberson
Walter Roberson 2011년 9월 21일
If your plane was along the z axis, then surf would not be able to handle it, as surf requires unique (x,y) for every z value.

댓글을 달려면 로그인하십시오.

Adam Danz
Adam Danz 2024년 10월 4일

0 개 추천

Starting in MATLAB R2024b, you can use constantplane to create a 2D plane in 3D axes. However, unlike surfaces and patches, the ConstantPlane will extend infinitely in all directions within the axis limits.
For example, to create a flat plane along the z axis at z=0,
constantplane('z',0)
grid on

댓글 수: 2

DGM
DGM 2024년 10월 4일
Finally! This is the logical extension of xline() and yline().
Looks like they also fixed the plane-plotting bug in fimplicit3 mentioned here.
load data E C ax
planefun=@(x,y,z) E(1)*x+E(2)*y+E(3)*z+E(4);
plot3(C(1), C(2),C(3),'rx'); axis(ax); hold on
fimplicit3(planefun,ax,EdgeColor='none',FaceAlpha=0.5); hold off

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

태그

질문:

bsd
2011년 9월 21일

댓글:

2024년 10월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by