15,112,217 members
Articles / Desktop Programming / Win32
Article
Posted 20 Nov 2008

60.5K views
31 bookmarked

Create temperature maps with 2D Voronoi diagrams

Rate me:
20 Nov 2008CPOL1 min read
A practicle application of 2D Voronoi diagrams.

Introduction

Voronoi Diagram is a useful mathematic abstraction which has many applications. You can read about it here and here. You can also see some examples here: Visualization of the 2D Voronoi Diagram and the Delaunay Triangulation and Fortune's Voronoi algorithm implemented in C#.

Background

Yesterday, I solved a problem: we have many weather centers and each weather center has coordinates (X, Y) and current temperature value (T). The goal of our solution was to create a temperature map.

Using the code

The structure `TemperatureLocation` stores data about the weather center: coordinates X, Y, and the temperature value.

C#
```public struct TemperatureLocation
{
private double x;

public double X
{
get { return x; }
set { x = value; }
}
private double y;

public double Y
{
get { return y; }
set { y = value; }
}
private double t;

public double T
{
get { return t; }
set { t = value; }
}

public TemperatureLocation(double x, double y, double t)
{
this.x = x;
this.y = y;
this.t = t;
}

public double GetDistance(TemperatureLocation tl)
{
return Math.Sqrt((this.x - tl.x) * (this.x - tl.x) +
(this.y - tl.y) * (this.y - tl.y));
}
}```

The class `VoronoiTemparature` is designed to create temperature maps. We load data about weather center, the parameters of the image (the color of cold and hot temperatures), and get the image of the map. For a more realistic map (without accurate Voronoi cells), use a simple smooth effect. The result of the test creation map can be seen on Figure 1.

Figure 1. Temperature map.

Points of interest

Creating temperature maps is really a problem in meteorology. For a good mapping, we must use interpolation algorithms (for a smooth isotherm). It is one of many Voronoi diagram applications (Voronoi died exactly 100 years ago, on 11-19-1908).

Share

 Software Developer Russian Federation
Hello! My name is Maxim Subbotin.

Now I work in sphere of web-development. I'm interesting researches in SEO field.
If you interesting, you can see this tool:

KeywordCompetitor

 First Prev Next
 pls help daskan8-Aug-09 0:35 daskan 8-Aug-09 0:35
 implementation in SharMap agelospanagiotakis15-Feb-09 4:23 agelospanagiotakis 15-Feb-09 4:23
 Re: implementation in SharMap Maxim_Barsuk15-Feb-09 22:49 Maxim_Barsuk 15-Feb-09 22:49
 Re: implementation in SharMap agelospanagiotakis16-Feb-09 3:04 agelospanagiotakis 16-Feb-09 3:04
 Re: implementation in SharMap agelospanagiotakis16-Feb-09 3:09 agelospanagiotakis 16-Feb-09 3:09
 Re: implementation in SharMap Maxim_Barsuk16-Feb-09 23:35 Maxim_Barsuk 16-Feb-09 23:35
 Re: implementation in SharMap agelospanagiotakis6-Mar-09 13:11 agelospanagiotakis 6-Mar-09 13:11
 Black areas are missing? nnononnnon14-Dec-08 8:26 nnononnnon 14-Dec-08 8:26
 Re: Black areas are missing? Maxim_Barsuk16-Dec-08 19:56 Maxim_Barsuk 16-Dec-08 19:56
 Hello! Its not error of algorithm, this problem is defect of graphic implementation. Сolor regions based on a set of triangles: Copy Code ```foreach (TemperatureLocation t in temperature) { Vector v = new Vector(t.X,t.Y); foreach (object obj in graph.Edges) { VoronoiEdge e = (VoronoiEdge)obj; if (((e.LeftData[0] == v[0]) & (e.LeftData[1] == v[1]))|((e.RightData[0] == v[0]) & (e.RightData[1] == v[1]))) { ... g.FillPolygon(brush, new Point[3] {new Point((int)v[0],(int)v[1]), new Point((int)e.VVertexA[0],(int)e.VVertexA[1]), new Point((int)e.VVertexB[0],(int)e.VVertexB[1])}); ... } } } ``` The black areas located near the borders charts, diagram's ribs here go to infinity: e.VVertexA[0] or e.VVertexA[1] is NaN. Smooth of image severely slowed construction of map: Copy Code ```public Bitmap GetMapTemperature(int weight, int height) { ... //return Smooth(bmp); return bmp; } ``` Thank you!
 Interesting... Paul Conrad20-Nov-08 10:47 Paul Conrad 20-Nov-08 10:47
 Date overflow laserbaronen20-Nov-08 2:50 laserbaronen 20-Nov-08 2:50
 Re: Date overflow Maxim_Barsuk20-Nov-08 5:26 Maxim_Barsuk 20-Nov-08 5:26
 Re: Date overflow Skymir20-Jul-09 5:25 Skymir 20-Jul-09 5:25
 Last Visit: 31-Dec-99 19:00     Last Update: 26-Nov-21 17:29 Refresh 1

General    News    Suggestion    Question    Bug    Answer    Joke    Praise    Rant    Admin

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.