Need help to draw lines.

조회 수: 3 (최근 30일)
Axelina Lindgren
Axelina Lindgren 2021년 5월 1일
답변: Prabhan Purwar 2021년 5월 7일
I need some help plotting lines going through the lens shape from (x, y)=(-10 0) to (0, 10) and I don't know how to do it even if I've tried several times I only get errors. I need a line from the starting point to the edge of the lens for different y:s. Then I need a line from that point straight over to the oposite side of the lens. Then i need a line from that point to the end point. I have tried different ways but I don't know how I am supposed to get the right x value for a certain y. Grateful for some help!
The code down below is for creating the lens shape.
clear
n1 = 1; %Refractive index air
n2 = 1.5; %Refractive index lens
D = 10; %Lens diameter
R = D./2; %Lens radius
d = 10; %Focal length
lopt = n1.*sqrt(d.^2 + R.^2); %Optical way when the ray does not diverge through the lens
Y = linspace(0, R, 1000);
X = linspace(0, d, 1000);
for ii = 1:length(Y)
LoptTemp = zeros(length(Y), length(Y));
L1(:,ii) = sqrt( (d-X).^2 + Y(ii).^2)*n1;
L2(:,ii) = X*n2;
LoptTemp(:,ii) = L1(:,ii) + L2(:,ii);
diffii(:,ii) = abs(LoptTemp(:,ii) - lopt);
[difference minIndex(ii)] = min(diffii(:,ii));
x_fit(ii) = X(minIndex(ii));
end
figure
plot(x_fit, Y, 'black');
hold on
plot(x_fit.*-1, Y, 'black');
hold on
plot(x_fit, -Y, 'black');
hold on
plot(x_fit.*-1, -Y, 'black');
hold on

답변 (1개)

Prabhan Purwar
Prabhan Purwar 2021년 5월 7일
Hi,
Kindly have a look at the following link for plotting lines.
File Exchange repositories such as Optometrika can act as a good starting point to learn about Optometric and it's implementation using MATLAB.
Hope it helps!!
Thanks

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by