Monday, September 20, 2010

stock technical terms

SMA: simple moving average

EMA: exponential moving average

MACD: Moving Average Convergence Divergence

KDJ Indicator:

RSI: relative strength index

Williams %R:

BIAS: bias ratio

Monday, July 19, 2010

about DSLR

DSLR
This is my guide for shopping DSLR (digital single lens reflector) lens and accessory.
The target machine is Canon 500d/T1i, which is classified as consumer DSLR. Other option may be 550d/T2i, which is newer. This ASP-C cropped frame machine. Real focal length is 1.6x the focal length marked on lenses.
I get 500d, which is best with EF-s lens. Here is a list of options I can upgrade the lens from the kit lens, which is EF-s 18-55 IS.

In EF-S lens range, there are three options consider most widely here for an upgrade still in wide-mid-telephoto range:
• EF-S 17-55mm f/2.8 IS USM, priced over $1,000. This is the best lens in this range. It provides the best IQ. But it lacks of range and also tagged high price. Note that this lens is the only constant aperture lens in the EF-s line. There is dust issue about this lens, but it can be solved by using UV filter.
• EF-S 15-85mm f/3.5-5.6 IS USM, priced over $700. The corresponding hood is 78E, the diameter for the lens is 72mm. Cost for lens, hood and UV filter would be just under $800.
• EF-S 17-85mm f/4-5.6 IS USM, priced over $400

Among all these three lenses, 15-85 would be the proper one after judging price, focal length range and IQ. But 17-55 definitely has the best reputation for image quality.

There are also wide to ultra-telephoto range lens, EF-S 18-135mm IS and EF-S 18-200mm IS. These lenses built quality is normal and believed comparable to kit lens 18-55 IS.

There are several ways to buy the lens, including eBay online shopping, online store and local store. Here some local stores are listed while I don’t have hand on experience of shopping with them yet.

First store I shall talk about is B&H, its tag is fair and often regarded as the baseline for deals. It has both online and local store. The store has pretty long history through.

Second, some reliable stores are 17photo.com, J&R, Ritzcamera, Calumet, Willoughby’s, tristate and 42th street photo.

There are also good online shopping stores like Amazon.com, beachcamera.com, newegg.com, dell.com, onecall.com, sigma4less.com, ibuydigital.com, samys.com and buy.com. Note that ibuydigital.com has the lowest tag for EF-S 15-85 while it may be a gray market item. All online store reputation can be checked on review site like, resellerrating.com, pricegrabber.com

Another item that is popular with lens is UV filter (ultraviolet filter). It’s a piece of glass used to prevent ultraviolet light through, which may cause blue foggy image. In reality, UV filter is used to protect expensive lens, to prevent first contact with other surface in situation like accidentally dropping. UV filter is specified by its diameter. The diameter for EF-S 15-85mm f/3.5-5.6 IS USM is 72mm. There are several UV filter brand and people believe more expensive filter means better filter. Hoya, Tiffen, B+W are common brands for UV filters. The cost for a good multi-coat filter would be up to $60.

Another protection to the lens and also good stuff for the photograph is the lens hood. The lens hood item number for EF-S 15-85mm f/3.5-5.6 IS USM is EW78E. Original brand hood is overpriced so get a cheap one.

There are also other accessories that are necessary for everyday shooting with DSLR, like tripod, flash, fast lens, underwater gear and bag. And in the following paragraph, we will talk about specification about these items that can guide the shopping.

Although tripod is not that important since the age of digital SLR, it’s still necessary for marginal light shooting or long time exposure. Any tripod will do the work, but more expensive tripod from Gitzo (best tripod), Bogen (best value/price) can provide better head which allows flexible adjustment and steady support.

For Canon DSLR, current line of flash is made of Speedlite 580EX II, Speedlite 430EX II and Speedlite 270EX. For macro shooting there are MT-24EX and MR-14EX. 580 comes with weather seal.

Below it’s a figure from Wikipedia which shows the common aperture size. Aperture controls the amount of light come through the lens. So aperture with larger size allows more light coming through so it allows shooting in dark place and faster shutter speed. Depth of field (DOF) is also determined by aperture, aperture with larger size will decrease depth of field. Aperture is often judged by speed and lens is called fast or slow by their aperture. Prime lens often has faster aperture than zoom lens. As far as I know, lens with aperture faster than f/2.8 can be considered as fast lens.


Underwater gear is helpful when shooting with water. There are two kinds here. One is waterproof gear and the other one is underwater gear. The latter one is more expensive that is often listed over the price of the camera. It gives control for each button of the camera while waterproof gear often is a water sealed plastic bag with hard housing for attached lens.

Saturday, July 10, 2010

kernel develop from zero

from:
http://www.julienlecomte.net/blog/2007/07/3/
http://www.omninerd.com/articles/Installing_GRUB_on_a_Hard_Disk_Image_File
http://kbarr.net/bochs
http://thestarman.pcministry.com/asm/mbr/PartTables.htm
http://members.iinet.net/~herman546/p20/GRUB2%20Bash%20Commands.html

make a fire ready disk image:
1. get a disk image file. There are two ways to get a empty disk image.
One is:
$ dd if=/dev/zero of=disk.img count=10080
The other one if Bochs is installed:
$ bximage: hd, flat, 1500, c.img
cyl=3047
heads=16
sectors per track=63
total sectors=3071376
total size=1499.70 megabytes
2. After having a disk image, we need partition table in it.
$ fdisk disk.img

x -> Extra functionality
c 10 -> 10 cylinders
h 16 -> 16 heads
s 63 -> 63 sectors per track
r -> Return to main menu
n -> Create a new partition
p -> Primary
1 -> Partition #1
1 -> First cylinder
10 -> Last cylinder
a -> Set bootable flag
1 -> Partition number
w -> Write partition to disk
3. to setup the loop back device.
first to find where the first partition start:
$ fdisk -l -u disk.img

Device Boot Start End Blocks Id System
disk.img1 * 63 10079 5008+ 83 Linux

Given one block is 512 bytes size.
Then, 63 * 512 = 32256
$ losetup -o 32256 /dev/loop0 disk.img
4. format the disk image
$ mkfs.ext2 /dev/loop0
5. mount the disk
$ mount -o loop /dev/loop0 /mnt
6. install GRUB
7. umount disk
$ umount /mnt
8. Detach the loopback device:
$ losetup -d /dev/loop0
9. Finish up the GRUB installation:
$ grub --device-map=/dev/null

device (hd0) disk.img
geometry (hd0) 10 16 63
root (hd0,0)
setup (hd0)
quit
10. Setup your .bochsrc file in the same directory as your disk image:
megs: 32
romimage: file=/usr/local/share/bochs/BIOS-bochs-latest, address=0xf0000
vgaromimage: file=/usr/local/share/bochs/VGABIOS-elpin-2.40
ata0-master: type=disk, path="disk.img", mode=flat, cylinders=10, heads=16, spt=63
cpu: count=1, ips=15000000
mouse: enabled=0
log: out.bochs
boot: disk

Saturday, June 26, 2010

song

如果没有你
往昔

Sunday, June 06, 2010

photography

卡尔•蔡司的历史

卡尔·蔡司

一个仅高中毕业的学徒工;德国古镇耶拿(Jena),卡尔·蔡司的故乡。当初也许谁也没有想到古镇上的这位学徒会成为世界光学巨子。

因为多年对光学和化学的兴趣,在学徒期满之后,卡尔长期在当地的耶拿大学(粉不错的大学,度假的好地方,可惜计算机专业......)旁听。1846年,30岁的卡尔创办了一个工作室,早期产品是放大镜片和简单的显微镜。得益于两位大科学家恩斯特·阿贝和奥托·肖特(听说过光学玻璃中大名鼎鼎的“肖特”玻璃吗?开创者就是此老)的帮助,蔡司厂光学镜头的质量一直处于领先地位。二战以前设在德累斯顿的生产车间,是世界上生产规模最大的照相机工厂。

一波三折的经历

1945年2月14日晚上,灾难降临,德累斯顿(明年一定要去逛逛这个易北河畔的佛罗伦萨)照相机工厂被盟军炸毁。在二战将近结束时,巴顿将军的第三军团占领了耶拿,由于雅尔塔条约规定美军的位置必须后退向西移,德国被一分为二,耶拿和德累斯顿全部由苏军占领。对于这个光学巨人的财富,俄国人当然不会让“美帝国主义”染指,作为战争赔偿,苏军拆除了剩下94%的工厂设备。在基辅建立了现在的Kiev( 基辅)照相机制造厂(借着这一丝血脉,俄罗斯镜头至今还能在光学领域占有一席之地)。但是德国人的技术好像抢不走,在耶拿大学的支持下“Carl Zeiss Jena”的标志很快又出现了。当初被巴顿掠走的126名蔡司关键管理人员和技师,在美国的支持下,也在联邦德国(西德)的奥伯考亨重新建厂。卡尔·蔡司在“资本主义”社会里也获得了新生,蔡司厂从此一分为二。





东德的产品冠名Carl Zeiss Jena(卡尔.蔡司.耶拿)史称“东蔡”,西德的产品冠名Carl Zeiss,史称“西蔡”,东、西蔡都标榜自己为是蔡司正宗,其实双方在设计上都秉承了蔡司传统。“塞翁失马,焉知非福”,正是这种竞争使得蔡司在光学技术上的更臻完美。

两德统一后,东西德的蔡司厂又联系经营。总部仍在奥伯考亨,拥有员工3500名,同时在世界各地设有分厂。这时的蔡司双剑合壁,在光学领域已经是第一强者。在135领域还尚有康太克斯与徕卡抗衡(康太克斯采用卡尔蔡司),但到了120领域Carl Zeiss 便称雄天下:哈苏、禄徕两大120巨头都使用卡尔蔡司镜头。进入数码时代,依靠蔡司的鼎力相助,原本是光学外行的索尼,摇身一变,成为消费级数码相机的业界老大之一。

经典的缔造者

蔡司开创了镜头工业中的诸多经典设计。蔡司的创始师保罗·鲁道夫就是镜头制造史上最有名的设计师之一。1890年,他设计出第一只消像散正光摄影镜(Anastigmat),开创了蔡司镜头的新纪元。1896年鲁道夫又发表了大名鼎鼎的普兰纳(Planar)双高斯结构的镜头,对各种镜头像差都进行了出色的纠正。此后,世界各地生产的各种品牌的标准镜头(包括徕卡)无不借鉴普兰纳镜头的设计。

1902年,他又设计出四片三组的“鹰之眼”——天塞(Tessar)镜头,虽然结构简单、价格适中,成像质量惊世骇俗,明快锐利。

其他诸如广角镜头的典范Holgon、大光圈镜头的典范Sonnar(索尼DSC-F828的镜头正是基于Sonnar镜头结构设计的)、专为旁轴相机设计的Bio-gon等等,都是蔡司创造的经典名镜。光学产品只要沾了蔡司镜头的边就有市场,这就是事实。

在蔡司、徕卡的耀眼光环下,罗敦司德(Rodenstock)和施奈德(Schneider)在外行人眼里变的默默无闻。其实在德意志百年的光学传统工业里曾经出现过大量的优秀品牌,但在蔡司、徕卡的垄断下大多凋零了,但罗敦司德和施奈德靠自己的一流的设计还坚强的存在。如果你看到哪款数码相机使用了罗敦司德和施奈德的镜头,其他的不说,光学性能尽可放心。虽然有传闻说数码相机用的德国镜头都只不过是德国设计甚至授权,但就算镜头在日本或其他什么地方OEM,德国人也会顾忌一点自己的面子,性能绝不会太离谱。

150 年历史的卡尔蔡司生产世界上屈指可数的高品质透镜。以其独有的色彩还原和成像特点令世界摄影爱好者爱不释手。HandyCam 里装备了变焦镜头 (Vario-Sonnar)(Vario-Tessa)。分辩率及对比性高,颜色还原出色,几乎没有四角失真现象。忠实提供高画质量摄影。同时,透镜T*(T star)表面涂层,抑制无用反射光,使图像更鲜明。[Vario·Sonnar]达到MTF指标 ※ ,生产中为确保质量,在透镜块上编上序号,在严格的质量控制下逐一生产出来的。





MTF※ (Modulation Transfer Function) 用于图像清晰度的描述,是目前分析镜头的解像力跟反差再现能力的方法。 :

Tessar镜头

1902 研制成功的“天塞”(Tessar)镜头以成像质量高、结构简单而风行世界, 享有“鹰眼”美誉。Handycam所配备的[Vario·Tessa],是Carle Zeisse 公司很好地运用 Tessar Lens 的高质量技术所开发的产品。







卡尔蔡司镜头

卡尔蔡司镜头是来自德国的品牌,是目前为数不多的非日系厂商。卡尔·蔡司是一家历史相当悠久的光学仪器厂商,其出品的镜头在传统相机领域向来都是“高贵”的代名词,许多色友以拥有卡尔·蔡司镜头为荣。索尼公司在自己的部分数码相机上使用了卡尔·蔡司镜头并以此为卖点。





卡尔蔡司镜头在业内一向享有良好的声誉,因其成像的超清晰能力而被称为“鹰之眼”,这种镜头一般情况下只有高端相机会配备这样的镜头。卡尔蔡司这家德国的老牌光学厂家已有一百多年的历史,生产世界上屈指可数的高品质透镜。以其独有的色彩还原和成像特点令全世界摄影家及爱好者爱不释手(但因其价格高高在上而敬而远之,望而却步)。分辩率高,颜色还原出色,几乎没有四角失真现象。忠实提供高画质摄影。其中带有红色T*为标志的镜头更是卡尔.蔡司引以为豪的产品。玩单反机的朋友都知道,在德国,大名鼎鼎的蔡司和莱卡如雷贯耳。在135领域还尚有康太克斯与徕卡抗衡(著名的康太克斯采用卡尔蔡司),但到了120领域卡尔.蔡司便称雄天下:哈苏、禄徕两大120巨头都使用卡尔.蔡司镜头。进入数码时代,依靠蔡司的鼎力相助,原本是光学外行的索尼,摇身一变,成为消费级数码相机的业界老大之一。

蔡斯历史

Zeiss 今天也许已经没有如同过去般地辉煌,也许已经不在那麼热衷商业性的镜头(成本的考量),但在最顶尖的光 学领 域,她仍然是一枝独秀。 翻开这近百年来的光学设计史,彷佛就是一部活生生的蔡司史,几位大师级的科学家,如 E. Abbe, P. Rudolph, Otto Schott, H. Harting, C.P.Goerz, L.J.Bertele..等等都是光学设计史上的关键人物。 十九世纪末Robert Koch 博士利用蔡司显微镜发现杆菌是导致结核病的原因。1911年挪威探险家Roald Amundsen首开 人类 踏上南极大陆,他用蔡司望远镜看南极大陆。大到人造xxx的空照镜头,小至眼镜玻璃,Zeiss 对各种光学玻璃的 制作乃 至光学设计上的突破,都在在的显示她对人类科学的 贡献,成就非凡。

【蔡司光学史 & 年表】

时至今日,世界上优良的光学系统很多,并非全然Zeiss 设计的系统就是最好,但所有经典的作品中Zeiss 所占的比例最重 却也是个公认的事实。以下仅例举几项最经典,也最被广为讨论的光学设计。 光学设计始於英国,但在E.Abbe之前几乎没有什麼很严格的理论基础,完全是尝试错误与经验的累积,而制造者多半是 机械工匠与玻璃师傅。

1868 E.Abbe建立全新的设计理论,如 Sine relation;定义各种Distortion及Abberation, 并确立光学计算的方法。同年并制 造出史上第一支,经由理论计算的显微镜。

1881 E.Abbe与Otto Schott 合作,开始有系统地研究并开发各种光学级的玻璃。

1886 Schott公司出版史上第一本光学玻璃目录,生产44种不同特性的光学玻璃,并为往后的新光学设计打下基础。

1890 Rudolph与Abbo 研发出史上第一支消散光像差的设计,Anastigmat,这项惊人的成就敲开了近代光学设计的大门,其 功劳不亚於贝尔发明电话。数年后推出商业化镜头,Zeiss Protar及Zeiss Planar。

1902 Rudolph 改良 Anastigmat 而推出最著名的商业化镜头 Zeiss Tessar f6.3 1911 Zeiss Biotar f1.8,设计者为M.V.Rohr

1919 第一次世界大战结束。

1923 Zeiss APO-Tessar

1929 Zeiss Biotar f1.0及f0.85 注: 在没有电脑辅助设计以前,大光圈的高速镜头设计是项很繁琐的工作,其「追迹」所计算的数学资料有时候必须要 好几千张才能完成。

1932 Sonnar f1.5及f2.0,设计者为L.Bertele这是当时世界上结像品质最佳的高速镜头。

1936 Sonnar 180mm f2.8这是史上第一支高速望远镜头。 Smakula 首开先例,在镜片上利用真空镀膜技术镀上一层低折射率的抗反射膜 Antireflection Coat-ings)T Coating

1945 第二次世界大战结束。

1948 西德蔡司成立 1952 R.Richter设计出18×18cm,90°视角之pleogon这是有史以来结像品质最佳的空照 镜。

1954 L.Bertele设计出 90°视角,没有形变的超广角镜,这支Biogon真可算是光学设计 史上的艺术极品。 Biogon 21mm f4.5 for 35mm 片幅 Biogon 38mm f4.5 for 6×6 片幅 Biogon 53mm f4.5 for 6×9 片幅 Biogon 75mm f4.5 for 9×12片幅 1954 G.Lange 设计出全新5 片组的Planar 80mm f2.8(R-olleiflex)Planar 可算是中距离 镜头,大光圈光学设计的希望,时至今日有很多知名厂牌的 50mm f1.4或是 50mm f2 都是采用类似planar Double Gauss 的光学设计。

1960 Planar 55mm f1.4 for Contarex

1961 Zeiss 数学家E.Glatzel 发表全新电脑辅助光学设计方法。

1964 Distagon 40mm f4 (哈苏6×6) 1966 Hologon 15mm f8 (35mm SLR) Planar 50mm f0.7(35mm SLR) Distagon 18mm f4 (35mm SLR)

1972 Distagon 35mm f1.4(Contax)非球面 Planar 85mm f1.4(Contax) Planar 50mm f1.4(Contax) Distagon 15mm f3.5(Contax) 1974 电影机 35mm 用的Distagon 35mm f1.2 及Distagon25mm f1.2

1976 再推出35mm电影机用的超广角超大光圈镜头Distagon18mm f1.2,你能想像它是 什麼可怕的模样吗? Planar 110mm f2(哈苏)

1982 浮动元件设计的Distagon 40mm f4(哈苏)

1984 第二阶(Secondary Spectrum)完全消色差的Tele-Apotessar 300mm f2.8

一个不得不提的名字---CONTAX

CONTAX简史

Saale河仍然流过德国工业城镇耶拿(Jena),这是Carl Zeiss基金会的故乡,耶拿就像那河流一样,尽管时光流逝,容颜未改。

1846年,Zeiss先生在这里创建了他的工作室,为耶拿大学制造高质量的放大镜片,就从这寒酸的陋室开始,Carl Zeiss作坊逐渐成长为世界上最大和最为领先的光学公司。
Carl Zeiss于1816年9月11日出生在图林根州(Thuringia States)的魏玛市(Weimar)。他父亲是魏玛王朝时代一个车削车间的工厂管理人员。卡尔在魏玛高级中学就读,并完成了六级课程。毕业后不久,他自愿给Frederick Koerner博士做学徒,Koerner博士当时正在研究用于望远镜目镜的玻璃。在学徒期满后,卡尔被耶拿大学短期聘用,并作为大学的旁听生。

从此,Zeiss开始了镜片制造的理论研究。在随后的几年里,Zeiss访问了斯图加特(Stuttgart)、达木斯塔特(Darmstadt)、韦恩(Wein)和柏林(Berlin)等城市里玻璃和镜片制造商,做了大量的笔记,内容涉及玻璃熔炼、材料、烧制温度和任何与玻璃制造、显微镜和其他光学仪器有关的题材。

他回到曾经在那里学习化学和数学的耶拿大学后,1846年,Zeiss刚满30岁,他开始在耶拿建立了工作室,有20个雇员,早期产品是放大镜片和简单的显微镜。1858年开始生产复合型显微镜。Carl Zeiss赢得了高质量产品的声誉,并于1861年在图林根州的展览会上获得了金牌。

Carl Zeiss所有的工作都是凭经验,既试错法来完成的。显然这种生产方法要消耗大量的时间和浪费大量的材料。Zeiss相信会有种科学的方法,能够更精确、可预见和更经济地生产镜片。Zeiss对此进行了五年的努力,最终无功而返。于是在1866年,他访问了耶拿大学,在那里遇到了当时在大学作讲师的Ernst Abbe.

Ernst Karl Abbe生于1840年元月23日,出生在Eisenach。Abbe在21岁时就毕业于Goettengen大学,1863年到耶拿大学工作,于1870年成为物理和数学教授。1878年成为天文和气象台的主管。1866年Abbe就以研究导师的身份加入了Zeiss的工作室,两人开始研究生产光学产品的科学基础结构。经过六年对新型光学玻璃的研究,终于在1872年制造出无与伦比的复合显微镜。这台仪器是今天所有现代复合显微镜的鼻祖。

在开始生产Carl Zeiss复合显微镜的第二年,1873年,Abbe发表了一篇科学论文,对如何设计完美的复合式显微镜的数学方法作了详细的描述,第一次详细地叙述了光学设计中的像差、衍射、慧型像差等内容。Abbe对光学过程描述得如此详细,以至于这篇论文成为了现代光学的基础。作为其发明的奖励,Carl Zeiss于1876年邀请Abbe作为合作者。
1879年,Abbe邀请了第三个合作伙伴Freidrick Otto Schott加入其阵营,共同致力于改进显微镜。当时Freidrick Otto Schott正在研究将锂加入到一种新型的光学玻璃,并致函给Abbe,说明其进展。Abbe博士立刻对这种新型玻璃产生了兴趣,随即对玻璃进行了测试,并高度地赞扬了Schott的研究结果。他们两人很快见了面,并形成了维系他们后半生的协议。Schott专门生产用于新型Carl Zeiss显微镜的玻璃,1884年建立了一个全面的工厂,其所有权归属于Carl Zeiss、Ernst Abbe和Freidrick Otto Schott,称为Jena Schott & Genossen光学工厂。Schott研制出100多种不同类型的光学玻璃,还有多种用于装饰及功能性玻璃。从此耶拿玻璃成为世界上最有名的玻璃。

我们是不是一直向往用一个机身通用各厂镜头?其实不夸张说,这个想法三十年前就已经实现了,那就是——M42螺口系统!

M42×1是三十年前风行一时的相机接口。它出现在二战前的德国,50年代起,由德国KW(Kamera-Werkstatten)推动此规格镜头盛行于世。许多著名相机生产厂都生产过M42×1接口镜头,如西德的Carl Zeiss、Schneider、Schacht、Enna、Rodenstock、Voigtlander、Kilfitt,东德的Carl Zeiss Jena、Meyer、Pentacon,法国的Angenieux,日本的Pentax、Fujica、Mamiya、Olympus、Yashica、Chinon、Cosina,美国的Vivitar等。目前俄罗斯和乌克兰还有M42螺口的镜头在生产,而且日本的Cosina公司又复古地推出了以Voigtlander为品牌的多款M42镜头和机身,看来,世界大一统的想法至今未绝。

那个时代是机械相机技术发展、工艺完善的一个巅峰时代,不管是机身还是镜头,都把它当作工艺品一样精心制作。因为同用一种接口,所以竞争十分激烈。镜头手感或成像稍不满意,用户就会换用别家的镜头,所以各个镜头生产厂都不惜成本,只为在竞争中领先。不像现在各个厂家都是各自为政,各有各的卡口,只能自己和自己比,用户不满意就得连机身一起换系统。

正是因为这个原因,M42时期的各个厂家生产的镜头基本上都是精品,做工考究,成像优良。那时的镜头,基本都是全金属结构,调焦手感极佳。成像嘛,现代镜头发展起来的是变焦技术,由此发展出了非球面镜和超低色散镜片。但这些技术对定焦镜头来说作用并不大,反而会大大增加成本,所以从成像质量来讲,30年前的定焦镜头表现已然十分优秀。

那时的理念是用尽量少的镜片来设计出最优秀的镜头,关键在设计,所以出现了一批经典结构。而现在镜片是能加就加,甚至个别镜头的镜片组合达到20片以上!那时的镜头全部用的是光学玻璃,而现在是模铸的甚至是有机玻璃的,再镀以增透膜,制造成本要比从前低多了。比较起来,只有在抗眩光技术上,由于早期M42镜头缺少多层镀膜技术,所以比现代镜头明显差上一截。

M42机身由于是三、四十年,甚至是五十年前的东西了,测光元件老化是一个普遍现象,而且那时用的电池目前早已不生产了,即使找到测光正常的机身,也得找现代电池替代。所以现在找二手的M42机身,不能苛求测光是否准确了,只能把它当纯手动相机来玩儿。我用过的M42机身有PENTAX SPF、FUJICA ST801、YASHICA TL ELECTRO X和最新出的Voigtlander Bessaflex TM。Voigtlander就不用说了,新机器嘛,各项指标都令人十分满意。

Friday, April 02, 2010

.vimrc

set nocompatible
source $VIMRUNTIME/vimrc_example.vim

set diffexpr=MyDiff()
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ '\ let cmd = '""' . $VIMRUNTIME . '\diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction

:filetype on
set expandtab
set sts=4
set shiftwidth=4
set foldcolumn=4
set guifont=Consolas:h9:cANSI
set guioptions=em
:colorscheme murphy
set lines=44
set columns=126

Monday, March 08, 2010

c++ copy constructor

#include

using namespace std;

class obj
{
public:
obj(int);
obj(const obj &);
int getvalue(void);
private:
int value;
};

obj::obj(int a)
{
value = a;
cout << "this is constructor" << endl;
}

obj::obj(const obj & ab) // <-- this is copy constructor format
{
value = ab.value; // <-- surprise!, in copy constructor you can use other obj's private value. real no surprise, thus other object is the same type. use a function will ruin the const prefix.
cout << "this is copy constructor" << endl;
}

int obj::getvalue(void)
{
return value;
}

int main(void)
{
obj obj1 = obj(1); // <-- this calls constructor
obj obj2(obj1); // <-- this calls copy constructor
return 0;
}

Sunday, March 07, 2010

graph work flow in latex document preparation under linux

Graphs make document illustrative.

Eps or pdf can be used in latex document preparation. But not both. Eps is great at vector graph and so is pdf while pdf can handle nature image as well but not for eps. So the choice is to use pdf as the output format for our document.

Use
\usepackage[pdftex]{graphicx}
in the latex header part, and in the body part, use
\includegraphics[width=2in]{graphname}
graphname is the file name for the graph without the tail .pdf.

There are two source of graph. One is computer generated, the other is natural image.
For compute generated, we take diagram as example.

1. Open Dia to draw the diagram.
2. Save as .dia so we can modify the diagram later.
3. Save as .eps so we still know the boundary.
4. use convert to convert eps to pdf.
5. Open the .pdf file in Inkscape. In page setup, use fit size to selected option after select the content box.
6. Save the output .pdf from Inkscape.

For the natural image
1. Use convert command to convert other format to pdf.
2. Use Inkscape again to trim the pdf to proper size.

Friday, March 05, 2010

emacs windows command and work flow

we cant split windows to have more windows and we can have different windows to have the same buffer or different buffers.

splitting windows:
cx 2 split vertically
cx 3 split horizontally

Using other windwos
cx o select next window

Displaying in another window
cx 4 b select buffer in next window and move to the next window
cx 4 co select buffer in next window
cx 4 f open file in next window
cx 4 d open dir in next window
cx 4 m start composing a mail message in another window
cx 4 . find a tag in the current tag table in another window
cx 4 r open a file readonly in the next window.

Deleting and Rearranging Windows
cx 0 kill the current window
cx 1 maximize the current window
cx ^ make selected window taller
cx } make selected window wider

Thursday, March 04, 2010

emacs buffer command and work flow

every content part in emacs is in a buffer, it's not necessary to have a buffer corresponding to a file. Usually we have a lisp interpreter buffer, text buffer and help buffer. Here a list of command around buffer is listed.

cx b switch buffers
cx k close buffer
cx 2 split buffer
cx 1 make the buffer where cursor in the only visible buffer
cx o Switch between the buffers on-screen
cx 4 b select a buffer but open in another window.
cx cb list existing buffer
cx cq toggle read only of the buffer
mx rename-buffer change the buffer name
mx view-buffer scroll through the buffer
cx k kill the buffer
mx kill-some-buffers offer kill buffer one by one
mx buffer-menu begin editing a buffer listing all emacs buffers, commands are:
d delete and move down, cd delete and move up, s save the buffer, ~ make buffer unmodified, x perform operation, u remove operation on current line and move down,

1 Select the buffer in a full-screen window.
2 set up two windows, with this buffer in one, and the previously selected buffer
f select the buffer in place of the `*Buffer List*' buffer.
o select the buffer in another window as if by C-x 4 b, leaving `*Buffer List*' visible.
q select this buffer, and also display in other windows any buffers previously flagged with the m command. If there are no such buffers, this command is equivalent to 1.
m Flag this buffer to be displayed in another window if the q command is used. The request shows as a `>' at the beginning of the line. The same buffer may not have both a delete request and a display request.

The following are some common work flow related to the buffer operation in the emacs.

I have read a file and want to look if there is other buffer opened: cx cb
then i want to switch back to let the working window has the full screen: cx 1
if I get other file to open, and want to switch to other buffer: cx b

learning emacs

Learning Emacs, get to know the following command:

program control:
cx cf open or create a file
cx cs save file
cx s save all open buffers
cx cw save file as
cx cc exit
cg cancel current command
cl redisplay screen and center on cursor
c/ undo action
cx d open directory

cursor movement
cn next line
cp previous line
cf forward a line
cb back a line
ca beginning of line
ce end of line
cv page down
av page up
a< move to beggining of file
a> move to end of file
ax goto-line n go to line n

Editing
ck kill line
cd erase next char
ad drase word
delete delete
c begin marking
cw delete region from begin of mark to current cursor position. content is moved to kill ring buffer
cy insert content of kill ring buffer at cursor position
ay if typed after a cy, it goes through nay entries in the kill ring and replaces the cy insert with the next former kill ring entry
aw copy content of region from marked begging to current cursor location into the kill ring buffer
ct transpose characters on either side of cursor
at transpose words on either side of cursor
cq escape the special meaning of the next char, if want to insert a control into the code, you type cq cc.
cc cc comment out a marked region
cu cc cc uncomment out the marked region.

Search and replace
cs search for string starting at the cursor. The line at the botton of the window hs you type in the string you search for. The search is donw as you type. To look for the next occurannce, hit cs again, and your last entry is used as the default search string. if you hist the bottom of the buffer, you type cs again to go back to the top.
cr reverse search. same as cs above, excpet it seraches backward from the cursor.
ax replace-string works from current cursor locatin. begins a two part dialog, the bottom of the it first asks for the string you want to search for, and then asks for what you want to replace it with. This operation immediately works on the entire buffer.
a% query replace string. works from current cursor location. begins a two part dialog, at the botton of the window it asks you waht you want to search for and then waht you want to search for and then waht want to replace it with. It then searches for each occurance of the string and highlights the match. If you want the replacement to occur, hit the space bar, if you want it to skip this match , hit the delete key.

Buffers, Regions, Windows
cx 2 split window into two equal sized buffers, one on top of the other
cx 3 split window into two equal sized buffers, on to the left/right of the other.
cx o move the cursor to the next buffer in the visible window
cx 5 2 create a new window, with the contents of the current buffer in the new window as well.
cx 1 if in a two buffer window, have the buffer that the cursor is in take up the entire window.
cx 0 if in a two buffer window, have the buffer that the cursor is not in take up the entire window
cx b shift back to the most recent buffer you were visiting prior to your current buffer
cx b filename shift to the named filename bufer
cx cb list all of the buffers currently perned. if the curosr is on a linein this buffer window, type an e will open that buffer in the current buffer, typing an o will open it in a second buffer in the current window.
cx k kill the current buffer. If the buffer is not saved you will be prompted to save it.

Printing
ax print-buffer prints the current buffer
ax print-region prints the current marked region

Command Shell
ax shell creates a command shell on the native os. all of emacs commands work within this shell for cutting and pasting.
ap yank command from prior command history
an next command from prior command history
cx k kill buffer and the shell along with it.

Saturday, February 20, 2010

logitech usb head set burn down

I have used two logitech usb head set, the latest one is A-0374A. I plug into usb slot but the usb chip burn down. Two are burn down like this. That's so sad. I search the net and find no posts about this issue. I will try to figure our the problematic chip and try to find logitech to give me replacement.

Wednesday, February 17, 2010

Uniform Spherical Distribution

http://en.wikibooks.org/wiki/Mathematica/Uniform_Spherical_Distribution


In this tutorial, we will plot a set of random, uniformly distributed, points on the surface of a sphere. This seems like a trivial task, but we will see that the "obvious" solution is actually incorrect. We will start off with this incorrect method, and then improve it to be correct.

[edit]Incorrect Method

The Spherical Coordinate system we are using.

In order to plot a point on a sphere's surface, we need two numbers: the colatitude, φ and the longitude, θ. We could use the latitude, which is given by 90°−φ, but colatitude is the conventional quantiity to deal with.

Now, we will make the simplistic assumption that we can use a uniform distribution for both the colatitude and longitude. We will plot 6000 points over a half sphere only, as this will allow us to see the results more clearly.

Let's define these distributions:

theta := RandomReal[ {0, Pi} ]; (* Uniform on [0,Pi], longitude, only goes halfway round*) phi   := RandomReal[ {0, Pi} ]; (* Uniform on [0,Pi], colatitude, from pole to pole *) 

You can easily alter the angle covered by changing the {0, Pi} to your desired boundaries.

Notice that we have used the "set delayed" operator (:=). We need this because when we build a table of the values in the next step, we want the Random[] function to be called for each entry. If we do not do this, the values of theta and phi will be set above and never changed, resulting in 6000 identical points. We now make the table of data:

dataPoints = Table[    {phi, theta},    {6000}]; 

Let's have a look at the distribution of the points:

rectPlot = ListPlot[   dataPoints,   AxesLabel -> {"\[Phi]", "\[Theta]"},   Ticks -> {     {0, Pi/4, Pi/2, 3 Pi/4, Pi},     {0, Pi/4, Pi/2, 3 Pi/4, Pi}}   ] 

This produces the following output. We see that the points indeed appear to be uniformly distributed.

Uniform Spherical Distribution 1.png

We will now map these spherical coordinates into the Cartesian space. This transformation is standard:

 x = r \sin\phi \cos\theta \,
 y = r \sin\phi \sin\theta \,
 z = r \cos\phi \,

For our purposes, we will set r=1. We make a function called sphericalToCartesian to transform each two-element coordinate {φ,θ} in the spherical system to a three-element coordinate,{x,y,z}, in the Cartesian system.

sphericalToCartesian[{phi_, theta_}] :=   {Sin[phi]*Cos[theta],    Sin[phi]*Sin[theta],    Cos[phi]}; 

We have a mapping, so all that remains is to apply it using the "map" operator, /@, which will perform this on each point in dataPoints:

mappedPoints = sphericalToCartesian /@ dataPoints; 

Now that we have a set of points in the Cartesian system, we would like to see them. We make a set of points located at each point inmappedPoints and show it. Here, we have the default view, and orthographic views from the top and front:

 points = Graphics3D[Point /@ mappedPoints];   Show[points]  Show[points, ViewPoint->{0,Infinity,0)}]  Show[points, ViewPoint->{0,0,Infinity)}] 
Uniform Spherical Distribution 2.png
Uniform Spherical Distribution 3.png
Uniform Spherical Distribution 4.png

We see that the points are certainly not distributed evenly - they are much more dense at the poles. This is because the mapping from spherical to Cartesian coordinates does not preserve area - the spherical space is pinched and compressed at the poles by the mapping. In order to fix this, we must alter our original distributions.

[edit]The Correct Method

In order to find the correct distribution for theta and phi, we must consider the Jacobian determinant of the mapping sphericalToCartesian. This will tell us how the spherical space is pinched by the transformation at each point.

We must find the Jacobian matrix first. We will leave r in for the moment, as Mathematica will be crunching the numbers. The evaluated Jacobian matrix is shown below, but we will let Mathematica work it out from the beginning.

J_F(r,\phi,\theta) =\begin{bmatrix} \dfrac{\partial x}{\partial r} & \dfrac{\partial x}{\partial \phi} & \dfrac{\partial x}{\partial \theta} \\[3pt] \dfrac{\partial y}{\partial r} & \dfrac{\partial y}{\partial \phi} & \dfrac{\partial y}{\partial \theta} \\[3pt] \dfrac{\partial z}{\partial r} & \dfrac{\partial z}{\partial \phi} & \dfrac{\partial z}{\partial \theta} \\ \end{bmatrix}=\begin{bmatrix}  	\sin\phi \cos\theta & r \cos\phi \cos\theta  & -r \sin\phi \sin\theta \\ 	\sin\phi \sin\theta &  r \cos\phi \sin\theta & r \sin\phi \cos\theta \\  	\cos\phi            & -r \sin\phi            &  0                     \end{bmatrix}.

We will construct this matrix very easily using the Outer[] function, which takes every possible combinations of each element except the first, and gives them as arguments to the function in the first element. Again, we must not evaluate this yet, as if we do, Mathematica will take the inputs f_ and x_ as "atomic," meaning that they cannot be broken down and therefore are unsuitable for inputs to Outer[].

jacMat[f_, x_] := Outer[D, f, x] 

This statement will take a list of directions (i.e. r, φ, θ), and a list of the same length of functions, which are the mappings taking these to the target space, in this case, Cartesian. This simple statement doesn't check that you have given it lists as inputs, and doesn't ensure they are same length. However, we know the lengths are right, so we won't bother with this.

We now define the list of directions. First, we must remove our previous definitions of phi and theta, (and r for good measure) as at the moment, they will inject a single random number each into the above statement, rather than a symbolic quantity. We also define the list of functions, which can be obtained by giving our now-symbolic directions as arguments to sphericalToCartesian.

Remove[r, phi, theta] dirs = {r, phi, theta} map = sphericalToCartesian[{r, phi, theta}] 

In order to find the Jacobian matrix and determinant, we now put:

jmat[map, dirs] Simplify[Det[%]] 

The output is:

{{Cos[theta] Sin[phi], -r Sin[phi] Sin[theta],  r Cos[phi] Cos[theta]},   {Sin[phi] Sin[theta],  r Cos[theta] Sin[phi],  r Cos[phi] Sin[theta]},   {Cos[phi],             0,                     -r Sin[phi]}} 
r^2 Sin[phi] 

We see that the Jacobian matrix is rearranged, but in Jacobians, it is exactly equivalent, as it just depends on the order of specification of the directions and functions. The Jacobian determinant is independent of the longitude, theta, so our uniform distribution in spherical coordinates will be uniform in Cartesian space. However, phi will not be, as as it changes, the Jacobian also changes. r also does this, but as we can just deal with a unit sphere, we can cut it out of the equation now.

There exists a method called the "Inverse CDF Method" which allows us to generate samples of a given probability density function from a set of uniformly distributed numbers between 0 and 1 (just like Mathematica's Random[]).

To use this method, we must first find the CDF of the PDF given by the Jacobian determinant. We normalise (to give a total probability of 1) by dividing by the area under the curve. <>t is a dummy variable.

area = Integrate[Sin[t], {t, 0, Pi}];(*Area under PDF*) cdf[y_] = Integrate[Sin[t]/area, {t, 0, y}](*CDF*) 

We now find the inverse of the CDF:

Solve[x == cdf[y], y](*Get distribution transform*) 
{{y -> -2 ArcSin[Sqrt[x]]}, {y -> 2 ArcSin[Sqrt[x]]}} 

We take the positive solution, and we can now set our theta and phi distributions:

 theta := RandomReal[ {0, Pi} ]; (* Uniform on [0,Pi], longitude, only goes halfway round*)  phi   := 2 ArcSin[Sqrt[Random[]]]; (* Colatitude, from pole to pole *) 

We now plot the points exactly as before:

dataPoints = Table[{phi, theta}, {6000}]; rectPlot = ListPlot[   dataPoints,   AxesLabel -> {"\[Phi]", "\[Theta]"},   Ticks -> {     {0, Pi/4, Pi/2, 3 Pi/4, Pi},     {0, Pi/4, Pi/2, 3 Pi/4, Pi}}   ] sphericalToCartesian[{phi_, theta_}] :=    {Sin[phi]*Cos[theta],     Sin[phi]*Sin[theta],     Cos[phi]};  mappedPoints = sphericalToCartesian /@ dataPoints; points = Graphics3D[Point /@ mappedPoints]; Show[points] Show[points, ViewPoint -> {0, 0, Infinity}] Show[points, ViewPoint -> {0, Infinity, 0}] 
Uniform Spherical Distribution 5.png

We have reduced the distribution density around the poles.

Uniform Spherical Distribution 6.png
Uniform Spherical Distribution 7.png
Uniform Spherical Distribution 8.png

We have now made it so that the points are evenly distributed over the spherical area.