1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab code for geometrical optics

  1. Jun 16, 2013 #1
    Hello all,

    i have frustrating task in my lab...

    i have to generate a code in MATLAB that will get the focal length and the object distance from the lens, i.e image (1000X1000 pixels).
    transfer it through the lens and, for the output it should be the result of it: inverse,magnified/shrinked version of the image. of course depends on the focal & distance of the object.
    this should be done considering that the lab is on geometrical optics...

    any help/reference would be appreciated

    my thought was to form a incidence matrix that will be transformed after multiplication with transfer matrix (Air,Lens,Air) and apply this matrix to the image matrix.
     
  2. jcsd
  3. Jun 16, 2013 #2

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member
    2016 Award

    Lets make sure I understand you:
    You have been given an image - and you need to know how far the object is.

    Presumably you know something about the lens-system and/or the object?

    My immediate approach would be to run the optics backwards - since geometric optics is reversible.
    I'd also just pick one point on the image as the "arrow head".

    But yeah - transfer matrix etc.
     
  4. Jun 17, 2013 #3
    we know all about the lens system: f,distance of from the object,distance of the image.
    i'm pretty lack of knowledge how to implement it with matlab. need for some sort of algorithm of how to do it.
     
  5. Jun 17, 2013 #4

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member
    2016 Award

    I'm not sure I see the problem - you know the image and object distances, the focal length, so you know the magnification (you have a formula for that?) So what is wrong with a script that takes these details as the input, calculates the magnification, and interprets it?

    i.e. how would you perform this task on paper?

    But now I suspect that I have not understood the problem ... what will the program take as input, what is to be assumed (i.e. is it always the same lens? Is it a thin lens? What?), and what is the output supposed to be? Try to be more careful in your description.
     
  6. Jun 17, 2013 #5
    ok, sorry,
    you understood very well the problem, but the implementation is not so obvious (for me i guess...).
    as an input i have:
    1)1000X1000 image.
    2)distance of the image from the lens
    3)focal length

    now i can calculate as you said the distance of the image after the lens & the magnification.
    that's the easy part.
    now i have to apply some algorithm that will take the original image and will transform it to the expected image,
    let's say that magnification was calculated and it equals 2.
    so i'm expecting to see a 2000x2000 magnified image upside down and mirrored.
    how do i map each of indices of the original image to the expected image ?
    example: the [(1,1)] pixel should be mapped to [(2000,2000)] pixel of the magnified version of the image.
     
  7. Jun 17, 2013 #6

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member
    2016 Award

  8. Jun 17, 2013 #7
    thought to do it in more "analytic" way...
    i accomplished the assignment as you suggested, but in this way there is no "lens" in the code only the outcomes.

    Code (Text):
    clear
    %Input object distance do
    do=15;
    %Input focal length of lens f
    f=-lO;
    % Input distance behind lens z
    z=30;
    %Input object ray coordinates ro
    ro-[O;1];
    To=[ 1 ,do;0,1 ];
    sf:[1,0;-(1/f),l];
    Ti=[ 1 ,z;0,1 ];
    S=Ti*Sf*To;
    %Check for determinant of overall matrix S
    detS=det(S)
    %"image" ray coordinate is ri
    ri=S*ro
    Output from MATLAB
    detS =
    1
    ri =
    0
    -0.5000
    variation of this code.
     
  9. Jun 17, 2013 #8

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member
    2016 Award

    Well done - sometimes it's just a mater of kickstarting the old grey matter.
     
  10. Jun 19, 2013 #9
    thanks for the help, Simon :)
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Matlab code for geometrical optics
Loading...