{"id":154,"date":"2021-03-31T14:00:00","date_gmt":"2021-03-31T21:00:00","guid":{"rendered":"https:\/\/www.lunarip.com\/?p=154"},"modified":"2021-03-30T14:00:31","modified_gmt":"2021-03-30T21:00:31","slug":"hilbert-curve-in-practice","status":"publish","type":"post","link":"https:\/\/www.lunarip.com\/index.php\/hilbert-curve-in-practice\/","title":{"rendered":"The Hilbert Curve in practice"},"content":{"rendered":"\n
In a previous post<\/a>, I introduced the concept of space filling curves and the ability to take a high dimension space and reduce it to a low or 1 dimension space. I also showed the complexity in 2 dimensions and in 3 dimensions of the Hilbert Curve<\/a> which I hope also provided an appreciation for the ability of the curve to traverse the higher dimension space. <\/p>\n\n\n\n In practice there are a number of implementations of the Hilbert curve mapping available in a number of languages including:<\/p>\n\n\n\n From galtay we have the following example where the simplest 1st order 2 dimension hilbert curve maps 4 integers [1,2,3,4] onto the 2 dimensional space <x,y> x = (0|1), y = (0|1)<\/p>\n\n\n\n its also possible to query the reverse transformation going from a point in the space to a distance along the curve. <\/p>\n\n\n\n On galtay’s repositary, there is a graphic that shows 1st order, 2nd order and 3rd order curves in an <x,y> space. The ranges represented by each of the curve get more resolution as the order increases: <\/p>\n\n\n\n As I have noted, an increase in the order of the curve, increases it complexity ( wiggleness) and its space covering measure and also provides more range quanta along the curve. <\/p>\n\n\n\n Returning to my suggestion in the earlier post, that the curve can be used to map a geographic space into the range and then have a entity (ip addresses which by themselves have no geographic relationship mapped not onto the range. in this fashion, subtraction along the range provides a (resolution dependant) measure of closeness of the location of these ip addresses. <\/p>\n\n\n\n Using galtay rendering of the 3 order curve shown in back, if one focuses on the value 8 along the curve, its specially close in 2 dimensions 13,12,11,10,9,7,6,2 but not specially close to 63 or 42 which are rendered outside the area shown. With simple subtraction we see can have rule that says ip addresses within 5\/6 units the 8 are close to whereas ip addresses with 20, 30,40 units distance are further away. As the order of the curve increases, this measurement get a better resolution. <\/p>\n\n\n\n <\/p>\n","protected":false},"excerpt":{"rendered":" In a previous post, I introduced the concept of space filling curves and the ability to take a high dimension space and reduce it to a low or 1 dimension space. I also showed the complexity in 2 dimensions and in 3 dimensions of the Hilbert Curve which I hope also provided an appreciation for […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"hide_page_title":"","_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":""},"categories":[12,13,7,6],"tags":[30,29,14,28],"yoast_head":"\n>>> from hilbertcurve.hilbertcurve import HilbertCurve\n>>> p=1; n=2\n>>> hilbert_curve = HilbertCurve(p, n)\n>>> distances = list(range(4))\n>>> points = hilbert_curve.points_from_distances(distances)\n>>> for point, dist in zip(points, distances):\n>>> print(f'point(h={dist}) = {point}')\n\npoint(h=0) = [0, 0]\npoint(h=1) = [0, 1]\npoint(h=2) = [1, 1]\npoint(h=3) = [1, 0]<\/code><\/pre>\n\n\n\n
>>> points = [[0,0], [0,1], [1,1], [1,0]]\n>>> distances = hilbert_curve.distances_from_points(points)\n>>> for point, dist in zip(points, distances):\n>>> print(f'distance(x={point}) = {dist}')\n\ndistance(x=[0, 0]) = 0\ndistance(x=[0, 1]) = 1\ndistance(x=[1, 1]) = 2\ndistance(x=[1, 0]) = 3<\/code><\/pre>\n\n\n\n
<\/figcaption><\/figure>\n\n\n\n