|

Various distances さまざまな距離

Distance is a common concept that we use day to day. It is a quantity that represents the length between two points. The most typical image of distance is that it is the length of a straight line drawn from one point to another.

距離は普段からよく使う当たり前の概念で、2点間の長さを表す量のことです。ある点からある点まで直線を引いた時の長さが距離というのが最も一般的なイメージでしょう。

However, if you think about it carefully, even in everyday life, the word “distance” often refers to something other than a straight line. For example, when we talk about the distance from home to a train station, we usually think of the length of a walk along streets. When we say that a place is “far away,” we are often thinking of the time it takes to travel there, not just the spatial distance. Kohei Sugiura’s “Time Map”, in which the map is deformed based on the time required to travel from the origin, visually expresses this everyday feeling. It is one of the most common methods of infographics to depict human relationships, similarities of data, etc., by replacing them with spatial distances.

しかし、日常でも良く考えると「距離」という言葉で直線的な距離以外のものを指していることが良くあります。例えば、家から駅までの距離という場合、大抵は直線距離ではなく道に沿って歩く長さを考えるでしょう。ある場所が「遠い」という場合、空間的な距離だけではなく移動にかかる時間のことを考えていることもあります。ある地点からの所要時間を距離に置き換えた杉浦康平の「時間地図」ではこの日常的な感覚が視覚的に表現されています。人間関係や、データの類似性などを空間的な距離に置き換えて描くのはインフォグラフィックスの常套手段のひとつです。

The flight distance from Tokyo to Sao Paulo is not a straight line distance between two points, but a curved length along the surface of the earth. This is called spherical geometry, and the shortest distance between two points is the length of an arc on the intersection of the sphere and a plane passing through the center of the sphere (the great circle). In Einstein’s world of relativity, the mass of matter bends space, so the shortest line between two points is also drawn along this curved space.

東京からサンパウロまでの飛行距離は2点間の直線距離ではなく、地球の表面に沿った曲線の長さになります。これは球面幾何学と呼ばれていて、2点間の最短距離は、球面と球の中心を通る平面との交線(大円)上の弧の長さになります。アインシュタインの相対性理論の世界では物質の質量が空間を曲げてしまうので、2点間を結ぶ最短の線もこの曲がった空間に沿って引かれることになります。

This way, distances can be measured in different ways depending on context and purpose. In mathematics, a metric space is a combination of a set and a distance function that determines the distance between the elements of the set. Technicalities aside, there are many interesting graphic possibilities when considering various functions for defining distances.

このように距離は文脈や目的によって違う測り方をすることができます。数学では集合に対してその元の間の距離を定める距離関数(distance function)を組み合わせたものを距離空間(metric space)と呼びますが、厳密な話はさておいてこの距離を求める関数を色々考えてみると図形的にも色々面白いことが考えられます。

The Euclidean distance

ユークリッド距離

The Euclidean distance is the most intuitive, ordinary linear distance between two points.

ユークリッド距離とは、2点間の最も直感的な、普通の直線距離のことです。

The geometry that Euclid summarized in his The Elements in the 3rd century B.C. is called Euclidean geometry, and it is pretty much the geometry that we study in junior high school and high school. Today, in order to distinguish various spaces, Euclidean space is defined as a space that uses the Euclidean distance explained below as the distance between two points. We classify different kinds of space by the way we measure distance.

紀元前3世紀にユークリッドが「原論」にまとめた幾何学がユークリッド幾何学と呼ばれますが、要は中学高校で習ういわゆる普通の幾何学のことです。現代では様々な空間を区別するために、2点間の距離として下記のユークリッド距離を定めた空間がユークリッド空間と呼ばれることになっています。距離を測る方法によって空間を分類するわけです。

The Euclidean distance on a plane is an equation like this, which is the hypotenuse of an isosceles triangle with the difference of the x coordinates as the base, and y coordinates as the height. It is one of the most frequently used formulas in games and graphics, such as when testing if a character is within the enemy’s attack range, or calculating the brightness of light based on the distance from the light source.

平面上のユークリッド距離はこんな式になり、要はx座標の差とy座標の差を直角三角形の底辺と高さとして、ピタゴラスの定理を使って斜辺の長さを求めたものになります。キャラクターが敵に近づいたら襲ってくる、とか、光の明るさを光源からの距離を元に計算する場合など、ゲームやグラフィックスでは最も多用する式のひとつです。

d=(x1x2)2+(y1y2)2{d={\sqrt {(x_{1}-x_{2})^{2}+(y_{1}-y_{2})^{2}}}}

Similarly in 3D, the equation goes like this

三次元の場合も同様で式はこうなります。

d=(x1x2)2+(y1y2)2+(z1z2)2{d={\sqrt {(x_{1}-x_{2})^{2}+(y_{1}-y_{2})^{2}+(z_{1}-z_{2})^{2}}}}

In general, the position of a point can be represented by multiple real numbers. Such as, a pair of x and y coordinates (x,y)(x, y) in two dimensions, x, y, z (x,y,z)(x, y, z) in three dimensions, and (a1,a2,...,an)(a1, a2,…, an) in n dimensions.

一般に、点の位置は実数の組で表すことができます。二次元であればx座標とy座標の組(x,y)(x, y)、三次元であればx, y, zの組(x,y,z)(x, y, z)、一般的にn次元であれば (a1,a2,,an)(a1, a2,…, an)といった形で表します。

Vector ベクトル

Euclidean distance defines the distance between two points,a1,a2,,an(a_1, a_2,…, a_n)and b1,b2,,bn(b_1, b_2,…, b_n)as below:

この時2点、a1,a2,,an(a_1, a_2,…, a_n)(b1,b2,,bn)(b_1 ,b_2, …, b_n) の間の距離dを、下のように定義したのがユークリッド距離です。

d=(b1a1)2+(b2a2)2++(bnan)2{d={\sqrt {(b_{1}-a_{1})^{2}+(b_{2}-a_{2})^{2}+\cdots +(b_{n}-a_{n})^{2}}}}

Manhattan Distance

マンハッタン距離

The Manhattan Distance is modeled after the distance you would walk in a grid-like city such as Manhattan, Kyoto, or Xian.

マンハッタン距離というのは、ニューヨークのマンハッタン、京都や西安のような碁盤状の都市を歩く時の距離をモデルにしたものです。

In a grid city, you can move only horizontally and vertically, but not diagonally across buildings. Therefore, the distance between two points is simply the sum of the (absolute value of) differences in x-coordinates and in y-coordinates.

碁盤状の街では縦横には進めますが建物を横切って斜めに進むことはできません。そのため2点間の距離は単純にx座標の差とy座標の差(の絶対値)を足し合わせたもにのなります。

d=x1x2+y1y2{d = |x_{1}-x_{2}| + |y_{1}-y_{2}|}

It look like this in 3D:

三次元の場合はこうなります。

d=x1x2+y1y2+z1z2{d = |x_{1}-x_{2}| + |y_{1}-y_{2}| + |z_{1}-z_{2}|}

And in general, the distance between two points (a1,a2,...,an)(a_1, a_2,…, a_n) and (b1,b2,...,bn)(b_1, b_2,…, b_n) in n-dimensions is:

そして一般にn次元の場合、2点a1,a2,,an(a_1, a_2,…, a_n)b1,b2,,bn(b_1, b_2,…, b_n)の間の距離はこうなります。

d=a1b1+a2b2+anbn{d = |a_{1}-b_{1}| + |a_{2}-b_{2}| \cdots + |a_{n}-b_{n}|}

Other distances

その他の距離

If you are interested, there are a lot more different kinds of distances in math. The distance we touched upon the sphere (spherical geometry) is an example, and conversely, you can think of the distance on a surface that is curved negatively, like a saddle or a Pringle chip. This is called hyperbolic geometry.

数学にはもっと様々な距離があります。上で触れた球面上の距離(球面幾何学)はその例ですが、逆に、鞍点やプリングルスチップのように負の向きに曲がった表面上の距離を考えることもできます。これは双曲幾何学と呼ばれます。

Both in spherical and hyperbolic geometry, Euclid’s parallel postulate doesn’t hold. In spherical geometry, there are no two straight lines that don’t cross each other, while in hyperbolic geometry, if you take a single line and a point not on the line, you can draw an infinite number of lines that don’t cross the original line. Distances work differently in these spaces too. On a sphere, distance is limited to half of the length of its circumference. On a hyperbolic surface, distances grow exponentially rather than linearly as you go further from the center.

ユークリッドの平行線の公理は球面幾何学と双曲幾何学の両方で、成り立ちません。球面幾何学では、交差しない2本の直線は存在しません。一方、双曲幾何学では、1本の直線と、その直線上にない1点があった場合、元の直線と交差しない無限個の直線を引くことができます。距離もこれらの空間上では異なる振る舞いをします。球面上では、距離は円周の半分の長さに制限されまが、双曲面上では、中心から離れるにつれて距離は線形ではなく指数関数的に増加します。

These are two examples of the spaces and distances you can get by “bending” a flat plane, and there are multidimensional versions of them. You can choose to bend the space non-uniformly, and the study of all these spaces in general is called Riemannian geometry. See also Non-Euclidean Spaces.

これらは平面を「曲げる」ことで得られる空間と距離の2つの例ですが、それぞれの多次元版も存在します。空間を均一でない方法で曲げることもでき、これらの空間を一般的に研究する分野はリーマン幾何学と呼ばれます。非ユークリッド空間も参照。

Hyperbolic geometry: en.wikipedia.org/wiki/Hyperbolic_geometry

You can even define distances between elements that aren’t part of geometric spaces. For example, you can think of a distance between two sets based on their overlap, where more shared elements mean they are “closer.” For instance, [apple, orange, cat] is closer to [mango, orange, cat] than to [apple, pineapple, dog]. In math, when you can define some kind of distance between elements using a function, those elements are said to belong to a metric space.

幾何学的な空間以外の要素の間にも距離を定義することができます。例えば、2つの集合の間の距離を、要素の重なり具合として、共通の要素が多いほど「より近い」とみなします。例えば、[りんご、オレンジ、猫] は [りんご、パイナップル、犬] より [マンゴ、オレンジ、猫] に近いと言えます。数学では、要素の間にある種の距離を関数としてで定義できる場合に、それらの要素は距離空間に属すると言います。

The definition of the distance between two sets above is problematic because the distance can significantly vary depending on the size of the sets. A better version is called Jaccard distance (or index) and is defined as:

この2つの集合間の距離の定義には問題があって、集合のサイズによって距離が大きく変わってしまいます。より良い方法には下のように定義されるジャカード距離(指数)があります。

dJ(A,B)=1ABAB\begin{aligned} d_J(A, B) = 1 - \frac{|A \cap B|}{|A \cup B|} \end{aligned}

Visualizing Distances 距離を視覚化する