C++ 真是一门很复杂的编程语言

Standard

用C++进行编程的时候总会碰到各种瓶颈,而每每仔细研究之后就会发现C++要比原想的那样复杂得多——它太庞大繁杂了:作为C的超集,又集成了各种编程范式,添加了诸如template等的诸多概念,C++已经算是不简单了,这还只是语法本身,更别提大工程之间各种代码之间的交互协调了。

学习C++

但是作为我的首席编程语言,我必须精通它才行,而现在才只是初窥门径。怎样才能快速提高呢?刚才在查资料的时候在stackoverflow上面看到了一段话提醒了我:

The only reasonable way to learn C++ is by reading... no matter how smart you are there is no way you can guess what the committee decided (actually being smart is sometimes even a problem because the correct answer is illogical and a consequence of historical heritage).

作为一个很少阅读大神代码的人可谓是吃尽了苦头——经常会碰到一些匪夷所思的问题,绞尽脑汁去思考,尝试,很久才发现这些问题都并不复杂,只是思维方式没有对而已。到底是因为我并没有专门的腾出来时间来读C++的书…(可惜真的有更重要的事要做)

我与C++

从初三的暑假算起到现在已经接触和“使用”C++将近4年半了,这期间对它的理解和掌握大概可以分三个阶段:

  • 刚开始的一年里几乎是完全以C的用法来使用C++的,没有任何面向对象的概念。
  • 再接着直到高三暑假接触了一些面向对象程序设计、C++核心的概念:类的一般用法,标准模板库的简单使用,基本上这段时间写的程序主要就是算法竞赛式的单文件程序
  • 最后就是从大学开始到现在这段时光,我明白了子类对基类的继承,类的多态(虚函数的使用)特性,以及接触了一些大型C++程序的代码,比如折腾了一段时间Havok物理引擎,写了一些上千行的东西,比如自己写的光线追踪器(ray tracer),以及现在正在写的计算几何库。

可以说现在我的C++编程水平仅仅是刚入门,因为高中的时光我的注意力主要是在算法和数据结构上面,对于编程语言本身并没有太在意(除了一些奇奇怪怪的错误让我不得不在意),而大一也并没有去学习很多进阶的内容(比如标准模板库是如何实现的,元编程(metarpogramming)等)

最后推荐一个书单,有各种讲解C++的书,总有一款适合你:D.

Written with StackEdit.

使用Stackedit进行写作

Standard

我经常在 stackexchange 编辑问题和答案,感觉它的编辑器异常的好用,比wordpress自带的TinyMCE舒服得多。
现在无意中发现了他们竟然把这个编辑器开源了:StackEdit,而且发现可以直接用这个编辑器发布到wordpress博客,这无疑对我这个长期被wordpress插件兼容问题折磨的人来说真是个天大的喜讯!

什么是Stackedit

引用官方的说明就是:

Full-featured, open-source Markdown editor based on PageDown, the Markdown library used by Stack Overflow and the other Stack Exchange sites.

以下是我主要看好的特点:

  • Markdown语法:用Markdown语法写文章会十分的方便,插入数学公式也变得异常容易(配合MathJax就可以直接写格式的公式,Stackedit 说明里面介绍了怎么使用MathJax
  • 离线与同步:这款编辑器可以直接以插件的方式直接在Chrome浏览器里面离线使用,所有文章都与blog、网盘的版本同步,根本不用担心文章丢失的问题。
  • WYSIWYG 所见即所得Markdown写文章不能边写边看文章的排版效果,必须等到写完之后才能看,而这个编辑器就实现了所见即所得!左侧是文章的脚本,右侧就是动态显示效果!如图
    enter image description here
  • 开源,免费

有了这个利器我的写作体验大大的提升了,在这里把它推荐给朋友们

Written with StackEdit.

How to determine whether 4 points are concyclic

Standard

Problem

Given 4 points in plane, how to determine they fall on a common circle?
There are lots of methods can do this, and here I introduce the determinant method, which is very straightforward, elegant and can easily generalized to quadratic curve.
The following content is inspired by this.
First of all, we can write the circle equation defined by by a determinant:

Proposition 1:

When , is inside the circle defined by ,and outside when , right on the circle when ,which means a circle go through simultaneously.

Proof:
Notice that:

( is the minor of the matrix)
and if we regard as a moving point, then is actually an equation of a circle:

i.e. the circle locate at
with radius .

When the circle equation become

So it’s clear that if fall inside that circle, then and vice versa.

Note: According to Cramer’s rule, is exactly the solution of the equation

And this 3 parameters perfectly define a circle pass through .One can easily verify when is or , by the equation above.

Generalization

We can generalize this method to the question of determine whether 6 points lies on some quadratic curve
Any equation of quadratic curve can write as (and again, we regard as a moving point )

and expand the last row of :

Definition.
A point is inside of a quadratic curve if there are no tangent of that curve pass through . And outside if there is at least 1 tangent pass through it.

And still we can tell whether lies in or out of by check the sign of .
Let be the coefficient of the quadratic equation, we have:

Proposition
The point lies inside of a quadratic curve If has the same sign with the determinant

But unfortunately I can’t give the proof temporarily. If you have any idea, please let me know, thanks in ahead!

Check the shape of the curve

If we want to check whether the six point lies on eclipse or hyperbola etc. we can simply check the sign of geometry invariants

Symbols.



Theorem.
The curve is classified by the following criterion:
Eclipse :
Parabola:
Hyperbola:
Two parallel lines :
Two intersecting lines:
A line( two line coincide):
Imaginary ellipse :
Point(two im. line intersect at real plane) :
Two parallel imaginary lines:

Robustness的中文翻译

Standard

Robust的翻译一直颇有争议,”鲁棒性”这种粗暴的音译保守人们诟病,而一种广泛被采纳的译法是“强健性,健壮性” 但是在大多数理工背景下Robust的意思应该是’Strong enough to withstand or overcome intellectual challenges or adversity’ 比如: the experiment yielded robust results

所以我认为翻译成“耐验的”不错,或者说“经验的”,虽然经验这个词已经有了新的意义。

3D俄罗斯方块

Standard

浏览Three.js例子的时候看到了一个叫cubeout的例子:

这个例子没有用webGL,而用的是html5的canvas。

玩这个稍稍费点脑力,不过只需一小会儿就会上手。另外注意下落中的物体块的框架叠在一起,有时很难分得清物体快的朝向