This is optical ray trace program that written with perl. You can use and rewrite, distribute freely.

簡単な光学系のための光線追跡プログラム.自由に書き換えて再配布して OK です.

perl program and example files
http://onohiroki.cycling.jp/perllens.zip

Example / 例

example.pl batch file

#!/usr/bin/perl
# ONO Hiroki onohiroki@cup.com
use strict;
use warnings;
use lib "./lib";
use Lens;

my $glassCatalog = GlassCatalog->new;
my $glass = Glass->new('BK7','SCHOTT','1.51680003','64.16738393');
$glassCatalog->add_glass($glass);
$glassCatalog->list;
my $wavelength = Wavelength->new->by_names('g','F','d','C');
my $lens = Lens->new('lens');
$lens->set_f_number(4);
$lens->wavelength($wavelength);
$lens->add_surface(0,1E16);
$lens->add_surface(100,10,$glass);
$lens->add_surface(-100,100);
$lens->add_surface(0,0);
$lens->set_indeces;
$lens->list;
$lens->save_dump("examplelens");

use Lens::PlotSVG;
my $h = 6;
my $svg = PlotSVG->new(init_x=>30,init_y=>20,lens_scale=>2);
my @rays = (
	RaySegment->new([1,0,0],[0,0,0],  [1,0,0],0),
	RaySegment->new([1,0,0],[0,$h,0], [1,0,0],0),
	RaySegment->new([1,0,0],[0,-$h,0], [1,0,0],0),
);
foreach my $r (@rays) {
	my $ray = $lens->skew_ray_trace($r);
	$svg->add($ray,'red');
}
$svg->add($lens);
$svg->save_as_file("plot.svg");
$ perl example.pl 

CATALOG: SCHOTT

                    Glass   Index(d) Abbe Number
     SCHOTT           BK7   1.516800   64.167384

lens
Surface#        Radius    Thickness      Glass              Index V-Value Semidiameter
 Object)        0.0000     Infinity                                                   
   Stop>      100.0000      10.0000        BK7 SCHOTT    1.516800  64.167             
      2)     -100.0000     100.0000        AIR                                        
 *Image)        0.0000       0.0000                                                   

List of Glasses:
                                                          g          F          d          C
                    Glass   Index(d) Abbe Number    435.835    486.133    587.562    656.273  
     SCHOTT           BK7   1.516800   64.167384   1.52672    1.52239    1.516800   1.51434  *


Reference Wavelength        d  587.562

 Wavelength        g        F        d        C
             435.835  486.133  587.562  656.273

                          
             Focal Length     98.42599 
                     Beta      0.00000 
    Front Principal Point      3.35354 
     Rear Principal Point     -3.35354 
  Entrance Pupil Distance      0.00000 
      Exit Pupil Distance    -11.75293 
          Object Distance        1e+16 
           Image Distance     95.07245 
     Front Image Distance     95.07245 
              Total Track    110.00000 


PlotSVG::new init_x:30 init_y:20

filename:plot.svg

Shell mode

Last login: Mon Aug 15 15:07:24 on ttys008
$ perl LensShell.pl 
Using Term::ReadLine::Stub
Welcome to Perl Lens Shell.
2 Glass Catalog Imported.
PerlLens> read examplelens
PerlLens> list

lens
Surface#        Radius    Thickness      Glass              Index V-Value Semidiameter
 Object)        0.0000     Infinity                                                   
   Stop>      100.0000      10.0000        BK7 SCHOTT    1.516800  64.167             
      2)     -100.0000     100.0000        AIR                                        
 *Image)        0.0000       0.0000                                                   

List of Glasses:
                                                          g          F          d          C
                    Glass   Index(d) Abbe Number    435.835    486.133    587.562    656.273  
     SCHOTT           BK7   1.516800   64.167384   1.52672    1.52239    1.516800   1.51434  *


Reference Wavelength        d  587.562

 Wavelength        g        F        d        C
             435.835  486.133  587.562  656.273

                          
             Focal Length     98.42599 
                     Beta      0.00000 
    Front Principal Point      3.35354 
     Rear Principal Point     -3.35354 
  Entrance Pupil Distance      0.00000 
      Exit Pupil Distance    -11.75293 
          Object Distance        1e+16 
           Image Distance     95.07245 
     Front Image Distance     95.07245 
              Total Track    110.00000 

PerlLens> exit
$ 

Input "help" for show help. You can read CODE V SEQ lens file and ZEMAX ZMX lens file. If you want to read CODE V lens data and/or ZEMAX lens data, you have to convert CODE V and ZEMAX glass data.

helpって入力すると簡単なヘルプが表示されます.CODE V と ZEMAX のガラスデータを変換しておけば,CODE V や ZEMAX のレンズデータを読み込む事ができます.

Glass data / ガラスデータ

CODE V glass data

Down load glasscatalogs.zip from ORA site.

glasscatalogs.zip contains the glass catalog data files. The glass data files are consisted from index and abbe number.
You can convert it with "read_cvglass_macrodata.pl". It generate ".

ORA のサイトから glasscatalogs.zip をダウンロードします.展開すると拡張し dat のデータファイルが得られます.これらは屈折率とアッベ数だけ含みます.これらを変換してガラスデータとして利用できます.

$ ls
LensShell.pl			lib				read_cvglass_macrodata.pl
glasscatalogs.zip		read_AGF_file.pl
$ unzip glasscatalogs.zip 
Archive:  glasscatalogs.zip
  inflating: Schott_Ohara_thermal.dat  
  inflating: schott.dat              
  inflating: pilkington.dat          
  inflating: ohara.dat               
  inflating: hoya.dat                
  inflating: hikari.dat              
  inflating: cornfr.dat              
  inflating: china.dat               
  inflating: chance.dat              
  inflating: cdgm.dat                
  inflating: CatalogFull.dat         
  inflating: sumita.dat              
$ perl read_cvglass_macrodata.pl 

CATALOG: HOYA

                    Glass   Index(d) Abbe Number
       HOYA         BAFL4   1.579572   53.706009
..........
$ mv CVGLASS lib/GLASS/
$ rm *.dat

ZEMAX glass data.

You can convert glass data file of ZEMAX with "read_AGF_file.pl".

ZEMAX の拡張子 AGF のガラスデータファイルを変換して利用できます.

$ ls
AGFGLASS			lib				schottzemax0210111.agf
HIKARI.agf			ohara_1101.agf			sumita.agf
HOYA20100506.agf		read_AGF_file.pl
LensShell.pl			read_cvglass_macrodata.pl
$ perl read_AGF_file.pl 

open HIKARI.agf HIKARI
open HOYA20100506.agf HOYA
open ohara_1101.agf OHARA
open schottzemax0210111.agf SCHOTT
open sumita.agf SUMITA
$ mv AGFGLASS lib/GLASS/
$ rm *.agf

Link