Points are the simplest and the smallest geometrical entity that can be defined. So a point cannot be broken down into smaller parts and it will always occupy the space of zero. Points do not have any width, or length either. So what are points?
Points are the basic construction unit of any geometrical object, and they can be represented as a vector of coordinates. Each coordinate of this vector represents the distance between this point and the corresponding axis I.e. the point {1,3} distance from the x axis is 1 and 3 from the y axis.
any code snippets can be found here.
I”m going to make the coding part in c++ but you can follow up in any language, with that said, this is our header file:
#ifndef POINT_POINT_H
#define POINT_POINT_H
#include <vector>
#include <string>
using namespace std;
class point {
public:
point(vector<float> &coords);
//geojson or wkt
point(string enc);
float distance(point * p2);
vector<float> coords();
bool inProximity(float tolerance, point * p);
string asGeojson();
string asWKT();
private:
vector<float>coordinates;
void fromGeojson(string p);
void fromWKT(string p);
};
#endif //POINT_POINT_H
Coordinates of a point
The order (size) of a vector representing a point must equal to the number of dimensions in the space in which we are considering this point i.e a point in a single dimension can only have one number p={x} as it’s coordinate, in 2d space that would be the familiar p={x,y}, in 3d that would be p={x,y,z} and so on on hyper dimensional space.
It is actually important to note that points cannot exists in zero or negative dimensions.
this would make up our constructor:
vector<float> point::coords() {
return coordinates;
}
Operations on points
Points are points, they do not width, length, space, orientation so there is only very little we can do using points alone. So we will start by discussing distances between points in this post, and in the upcoming post we will discuss points cloud and point clusters. Simple as they are, points are essential to understand as every other geometrical object will depend on it, and have relations to points (along, inside, on parameter, outside, centroids, …)
points can be created of course, as we have discussed before, we need coordinates to create a point and that is it.
points have distances among them, and this is the only operation in this post.
distance between two points in 1D plain is simple just get the absolute differences between their coordinates for example the distance between p0={3}, p1={5} is simply 2 abs(3-5);
in 2D the formula becomes a little more complicated, it will involve the use Pythagoras theorem. In order to calculate the distance between two points, we will need to form a virtual right angle triangle between those points as shown blew:

this triangle will have a base of abs(p1[0] – p0[0]) and a hight of abs(p1[1] – p0[1]) thus naturally the distance between p0 and p1 is given by sqrt(width^2 – hight^2).
So we can deduce a more general formula for calculating the distance between two points as follows:
float point::distance(point *p2) {
if(coordinates.size()!=p2->coordinates.size())return -1;
double sum = 0;
for (int i = 0 ; i<coordinates.size();i++) {
sum += pow(abs(coordinates[i]-p2->coordinates[i]),2);
return sqrt(sum);
}
}
we can build up on this function another one that is fairly used too, this function checks if the two points are in close proximity to each other (we may require that the caller should specify the proximity tolerance), anyway the proximity function simply checks if the distance between two points are within a given tolerance as follows:
bool point::inProximity(float tolerance, point * p) {
float dist= distance(p);
if(dist<tolerance)return true;
return false;
}
Next posts will cover points on spheres (like earth) and projections.
Representations of a point
perhaps the most famous representations of a point are the WKT and GeoJSON formats:
and they are quite simple, for example the GeoJSON format is as follows:
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
x,
y,
z
]
}
}
the generation of a geoJSON representation of a point, is quite straight forward:
string point::asGeojson() {
string geojson = "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[";
for(float c : coordinates){
geojson+= to_string(c) + ",";
}
geojson.substr(0, geojson.size()-1);
geojson +="]}}";
return geojson;
}
while the wet representation is as follows:
POINT( x y z ...)
and the code generator function look like this:
string point::asWKT() {
string wkt = "POINT(";
for(float c : coordinates){
wkt+= to_string(c) + " ";
}
wkt +=")";
return wkt;
}
I’ll leave the point constructor that parses GeoJSON or WKT as an exercise for the user.

One thought on “Points”