Date:2024-03-13
How to create Minkowski Distance Circles with Processing.
This article describes how to create shapes (circles) using Minkowski distance with Processing.
Index
- Sample Graphic of barbe_generative_diary
- What is Minkowski Distance?
- Understanding Different Orders of Minkowski Distance
- How to create a Minkowski Distance Circles with Processing
- Recommended Book / Generative art for beginner
Sample Graphic of barbe_generative_diary
This is a barbe_generative_diary’s graphic sample using Minkowski Distance.
In the realm of data science and machine learning, metrics play a pivotal role in quantifying the similarity or dissimilarity between data points. One such metric that holds significant importance is the Minkowski distance. Named after the German mathematician Hermann Minkowski, this distance measure serves as a versatile tool in various fields, including pattern recognition, image processing, and clustering analysis. Let’s delve deeper into what Minkowski distance entails and how it creates circles using Minkowski distance with program code.
What is Minkowski Distance?
Minkowski distance is a generalized metric that calculates the distance between two points in a multidimensional space. It is essentially a measure of dissimilarity between two vectors in a normed vector space. The formula for calculating the Minkowski distance between two points, X and Y, in an n-dimensional space is given by:
- D(X,Y) represents the Minkowski distance between points X and Y.
- xi and yi are the corresponding components of the two points in the i th dimension.
- p is a parameter that defines the order of the Minkowski distance. When p=1, it corresponds to the Manhattan distance, and when p=2, it represents the Euclidean distance.
Understanding Different Orders of Minkowski Distance
- Manhattan Distance (p=1): Also known as city block distance or taxicab distance, the Manhattan distance calculates the distance between two points along the grid-like paths. It is computed as the sum of the absolute differences of their Cartesian coordinates.
- Euclidean Distance (p=2): Perhaps the most familiar distance metric, the Euclidean distance represents the straight-line distance between two points in space. It is derived from the Pythagorean theorem and measures the length of the line segment connecting the two points.
- Other Orders: Minkowski distance isn’t restricted to just p=1 and p=2. It can accommodate any real number p≥1. Higher values of p give more weight to large differences in one dimension, whereas lower values spread the weight more evenly.
The following figure shows unit circles (the level set of the distance function where all points are at the unit distance from the center) with various values of p
How to create a Minkowski Distance Circles with Processing
The code below is created separately for each HALF_PI.
//Minkowski distance|Circles
float radius = 200;
void setup() {
size(500, 500);
noFill();
}
void draw() {
background(255);
translate(width / 2, height / 2);
noStroke();
fill(0,100);
minkowskiCircles();
}
void minkowskiCircles() {
float[] pValues = {0.5, 1, 2, 3};
for (float p : pValues) {
beginShape();
for(int i=0; i<4; i++){
for (float angle = 0; angle < HALF_PI; angle += 0.01) {
float x = cos(angle + HALF_PI*i);
float y = sin(angle + HALF_PI*i);
float scale = pow(pow(abs(x), p) + pow(abs(y), p), 1/p);
vertex(radius * x / scale, radius * y / scale);
}
}
endShape(CLOSE);
}
}
Result:
Recommended Book / Generative art for beginner
Generative Art: A Practical Guide Using Processing – Matt Pearson
Generative Art presents both the techniques and the beauty of algorithmic art. In it, you’ll find dozens of high-quality examples of generative art, along with the specific steps the author followed to create each unique piece using the Processing programming language. The book includes concise tutorials for each of the technical components required to create the book’s images, and it offers countless suggestions for how you can combine and reuse the various techniques to create your own works.
Purchase of the print book comes with an offer of a free PDF, ePub, and Kindle eBook from Manning. Also available is all code from the book.
—–
► Generative Art: A Practical Guide Using Processing – Matt Pearson
Publication date: 2011. July