[{"data":1,"prerenderedAt":1082},["ShallowReactive",2],{"tutorial-fast-geodesic-distances-in-python":3},{"id":4,"title":5,"author":6,"body":7,"date":1059,"description":1060,"extension":1061,"keywords":1062,"meta":1073,"navigation":140,"ogImage":1074,"path":1075,"published":140,"seo":1076,"stem":1077,"tags":1078,"__hash__":1081},"tutorials\u002Ftutorials\u002Ffast-geodesic-distances-in-python.md","Fast and Accurate Geodesic Distances in Python","Žiga Sajovic",{"type":8,"value":9,"toc":1047},"minimark",[10,28,44,48,55,60,85,95,99,166,176,218,222,225,257,263,266,269,319,322,325,393,397,400,403,406,545,551,554,557,603,607,614,668,674,685,689,692,756,762,765,769,772,780,852,858,865,868,923,930,942,946,952,956,986,990,997,1001,1013,1018,1021,1027,1039,1043],[11,12,13],"note",{},[14,15,16,17,22,23,27],"p",{},"Also available in ",[18,19,21],"a",{"href":20},"\u002Ftutorials\u002Ffast-geodesic-distances-in-cpp","C++"," and ",[18,24,26],{"href":25},"\u002Ftutorials\u002Ffast-geodesic-distances-in-javascript","JavaScript",".",[14,29,30,31,35,36,39,40,43],{},"A geodesic distance is the distance from a point to a seed, measured along the surface of a mesh. Straight-line distance cuts through the object. Geodesic distance walks over it. ",[32,33,34],"code",{},"trueform"," computes it with one call, ",[32,37,38],{},"tf.geodesic_distances",", new in version 0.10.8. One ",[32,41,42],{},"pip install",". NumPy arrays in, NumPy arrays out. This tutorial covers one seed, many seeds, a bounded radius, float32 and float64, and turning distances into rings and patches.",[45,46],"article-cta",{":buttons":47},"[{\"label\":\"trueform\",\"to\":\"\u002Ftrueform\",\"icon\":\"i-lucide-cpu\",\"variant\":\"soft\",\"color\":\"neutral\"},{\"label\":\"GitHub\",\"to\":\"https:\u002F\u002Fgithub.com\u002Fpolydera\u002Ftrueform\",\"icon\":\"i-simple-icons-github\",\"variant\":\"soft\",\"color\":\"neutral\"},{\"label\":\"Documentation\",\"to\":\"https:\u002F\u002Ftrueform.polydera.com\u002Fpy\u002Fmodules\u002Fgeometry#geodesic_distances\",\"variant\":\"soft\",\"color\":\"neutral\"}]",[14,49,50],{},[51,52],"img",{"alt":53,"src":54},"Geodesic distance from one seed on the Stanford dragon, teal to orange, with iso-distance lines","\u002Fimg\u002Ftutorials\u002Fgeodesic-distances.png",[56,57,59],"h2",{"id":58},"install","Install",[61,62,67],"pre",{"className":63,"code":64,"language":65,"meta":66,"style":66},"language-bash shiki shiki-themes github-dark","pip install trueform\n","bash","",[32,68,69],{"__ignoreMap":66},[70,71,74,78,82],"span",{"class":72,"line":73},"line",1,[70,75,77],{"class":76},"svObZ","pip",[70,79,81],{"class":80},"sU2Wk"," install",[70,83,84],{"class":80}," trueform\n",[14,86,87,88,94],{},"You need version 0.10.8 or later. See the ",[18,89,93],{"href":90,"rel":91},"https:\u002F\u002Ftrueform.polydera.com\u002Fpy\u002Fgetting-started\u002Finstallation",[92],"nofollow","installation guide"," for all options.",[56,96,98],{"id":97},"loading-the-mesh","Loading the mesh",[61,100,104],{"className":101,"code":102,"language":103,"meta":66,"style":66},"language-python shiki shiki-themes github-dark","import trueform as tf\nimport numpy as np\n\nmesh = tf.Mesh(*tf.read_stl(\"part.stl\"))\n","python",[32,105,106,122,135,142],{"__ignoreMap":66},[70,107,108,112,116,119],{"class":72,"line":73},[70,109,111],{"class":110},"snl16","import",[70,113,115],{"class":114},"s95oV"," trueform ",[70,117,118],{"class":110},"as",[70,120,121],{"class":114}," tf\n",[70,123,125,127,130,132],{"class":72,"line":124},2,[70,126,111],{"class":110},[70,128,129],{"class":114}," numpy ",[70,131,118],{"class":110},[70,133,134],{"class":114}," np\n",[70,136,138],{"class":72,"line":137},3,[70,139,141],{"emptyLinePlaceholder":140},true,"\n",[70,143,145,148,151,154,157,160,163],{"class":72,"line":144},4,[70,146,147],{"class":114},"mesh ",[70,149,150],{"class":110},"=",[70,152,153],{"class":114}," tf.Mesh(",[70,155,156],{"class":110},"*",[70,158,159],{"class":114},"tf.read_stl(",[70,161,162],{"class":80},"\"part.stl\"",[70,164,165],{"class":114},"))\n",[14,167,168,171,172,175],{},[32,169,170],{},"tf.read_obj"," works the same way. If you already have NumPy arrays, pass them to ",[32,173,174],{},"tf.Mesh(faces, points)",". To follow along without a file, make a unit sphere:",[61,177,179],{"className":101,"code":178,"language":103,"meta":66,"style":66},"faces, points = tf.make_sphere_mesh(1.0, 200, 400)\nmesh = tf.Mesh(faces, points)\n",[32,180,181,209],{"__ignoreMap":66},[70,182,183,186,188,191,195,198,201,203,206],{"class":72,"line":73},[70,184,185],{"class":114},"faces, points ",[70,187,150],{"class":110},[70,189,190],{"class":114}," tf.make_sphere_mesh(",[70,192,194],{"class":193},"sDLfK","1.0",[70,196,197],{"class":114},", ",[70,199,200],{"class":193},"200",[70,202,197],{"class":114},[70,204,205],{"class":193},"400",[70,207,208],{"class":114},")\n",[70,210,211,213,215],{"class":72,"line":124},[70,212,147],{"class":114},[70,214,150],{"class":110},[70,216,217],{"class":114}," tf.Mesh(faces, points)\n",[56,219,221],{"id":220},"distance-from-one-seed","Distance from one seed",[14,223,224],{},"A seed is a point id. The result has one distance per point.",[61,226,228],{"className":101,"code":227,"language":103,"meta":66,"style":66},"d = tf.geodesic_distances(mesh, [0])\n# d: np.ndarray, shape (num_points,), the mesh's dtype\n# d[0] == 0.0\n",[32,229,230,246,252],{"__ignoreMap":66},[70,231,232,235,237,240,243],{"class":72,"line":73},[70,233,234],{"class":114},"d ",[70,236,150],{"class":110},[70,238,239],{"class":114}," tf.geodesic_distances(mesh, [",[70,241,242],{"class":193},"0",[70,244,245],{"class":114},"])\n",[70,247,248],{"class":72,"line":124},[70,249,251],{"class":250},"sAwPA","# d: np.ndarray, shape (num_points,), the mesh's dtype\n",[70,253,254],{"class":72,"line":137},[70,255,256],{"class":250},"# d[0] == 0.0\n",[14,258,259],{},[51,260],{"alt":261,"src":262},"Distance from one seed, computed on the Stanford bunny: geodesic distance from point 0 at the nose, teal near to orange far, with pink rings of equal distance","\u002Fimg\u002Ftutorials\u002Fsteps\u002Ffast-geodesic-distances-1-seed.png",[14,264,265],{},"The distance is zero at the seed. On the unit sphere, the farthest point is the opposite pole, at a distance close to π.",[14,267,268],{},"You can check the result on this sphere. The exact geodesic distance on a unit sphere is the great-circle angle:",[61,270,272],{"className":101,"code":271,"language":103,"meta":66,"style":66},"exact = np.arccos(np.clip(points @ points[0], -1.0, 1.0))\nprint(np.abs(d - exact).max())\n",[32,273,274,306],{"__ignoreMap":66},[70,275,276,279,281,284,287,290,292,295,298,300,302,304],{"class":72,"line":73},[70,277,278],{"class":114},"exact ",[70,280,150],{"class":110},[70,282,283],{"class":114}," np.arccos(np.clip(points ",[70,285,286],{"class":110},"@",[70,288,289],{"class":114}," points[",[70,291,242],{"class":193},[70,293,294],{"class":114},"], ",[70,296,297],{"class":110},"-",[70,299,194],{"class":193},[70,301,197],{"class":114},[70,303,194],{"class":193},[70,305,165],{"class":114},[70,307,308,311,314,316],{"class":72,"line":124},[70,309,310],{"class":193},"print",[70,312,313],{"class":114},"(np.abs(d ",[70,315,297],{"class":110},[70,317,318],{"class":114}," exact).max())\n",[14,320,321],{},"The difference is small, and it shrinks as the sphere gets finer.",[14,323,324],{},"Most of the time the seed is a position, not an id. Find the nearest mesh point first:",[61,326,328],{"className":101,"code":327,"language":103,"meta":66,"style":66},"cloud = tf.PointCloud(mesh.points)\nseed, dist2, _ = tf.neighbor_search(\n    cloud, np.array([0.0, 0.0, -1.0], dtype=np.float32))\n\nd = tf.geodesic_distances(mesh, [seed])\n",[32,329,330,340,350,379,383],{"__ignoreMap":66},[70,331,332,335,337],{"class":72,"line":73},[70,333,334],{"class":114},"cloud ",[70,336,150],{"class":110},[70,338,339],{"class":114}," tf.PointCloud(mesh.points)\n",[70,341,342,345,347],{"class":72,"line":124},[70,343,344],{"class":114},"seed, dist2, _ ",[70,346,150],{"class":110},[70,348,349],{"class":114}," tf.neighbor_search(\n",[70,351,352,355,358,360,362,364,366,368,370,374,376],{"class":72,"line":137},[70,353,354],{"class":114},"    cloud, np.array([",[70,356,357],{"class":193},"0.0",[70,359,197],{"class":114},[70,361,357],{"class":193},[70,363,197],{"class":114},[70,365,297],{"class":110},[70,367,194],{"class":193},[70,369,294],{"class":114},[70,371,373],{"class":372},"s9osk","dtype",[70,375,150],{"class":110},[70,377,378],{"class":114},"np.float32))\n",[70,380,381],{"class":72,"line":144},[70,382,141],{"emptyLinePlaceholder":140},[70,384,386,388,390],{"class":72,"line":385},5,[70,387,234],{"class":114},[70,389,150],{"class":110},[70,391,392],{"class":114}," tf.geodesic_distances(mesh, [seed])\n",[56,394,396],{"id":395},"distance-from-many-seeds","Distance from many seeds",[14,398,399],{},"Pass several ids. Each point gets the distance to its nearest seed.",[14,401,402],{},"The seeds can be a whole curve. Then the field is the distance from that curve, measured along the surface. That is the distance from an edge: an offset from a trim line, a falloff from a seam.",[14,404,405],{},"Take the bunny and cut it in half. The cut is the boundary of the half. Its points are the seeds:",[61,407,409],{"className":101,"code":408,"language":103,"meta":66,"style":66},"bunny = tf.Mesh(*tf.read_stl(\"bunny.stl\"))\n\n# cut it at the middle height; the bunny stands along y\nheight = bunny.points[:, 1]\nmiddle = 0.5 * (height.min() + height.max())\n(faces, points), _, _ = tf.isobands(bunny, height, middle, selected_bands=[1])\nhalf = tf.Mesh(faces, points)\n\n# the cut is the open boundary of the half\ncut = tf.boundary_paths(half).data   # point ids on the cut\nfrom_cut = tf.geodesic_distances(half, cut)\n",[32,410,411,429,433,438,454,476,499,509,514,520,534],{"__ignoreMap":66},[70,412,413,416,418,420,422,424,427],{"class":72,"line":73},[70,414,415],{"class":114},"bunny ",[70,417,150],{"class":110},[70,419,153],{"class":114},[70,421,156],{"class":110},[70,423,159],{"class":114},[70,425,426],{"class":80},"\"bunny.stl\"",[70,428,165],{"class":114},[70,430,431],{"class":72,"line":124},[70,432,141],{"emptyLinePlaceholder":140},[70,434,435],{"class":72,"line":137},[70,436,437],{"class":250},"# cut it at the middle height; the bunny stands along y\n",[70,439,440,443,445,448,451],{"class":72,"line":144},[70,441,442],{"class":114},"height ",[70,444,150],{"class":110},[70,446,447],{"class":114}," bunny.points[:, ",[70,449,450],{"class":193},"1",[70,452,453],{"class":114},"]\n",[70,455,456,459,461,464,467,470,473],{"class":72,"line":385},[70,457,458],{"class":114},"middle ",[70,460,150],{"class":110},[70,462,463],{"class":193}," 0.5",[70,465,466],{"class":110}," *",[70,468,469],{"class":114}," (height.min() ",[70,471,472],{"class":110},"+",[70,474,475],{"class":114}," height.max())\n",[70,477,479,482,484,487,490,492,495,497],{"class":72,"line":478},6,[70,480,481],{"class":114},"(faces, points), _, _ ",[70,483,150],{"class":110},[70,485,486],{"class":114}," tf.isobands(bunny, height, middle, ",[70,488,489],{"class":372},"selected_bands",[70,491,150],{"class":110},[70,493,494],{"class":114},"[",[70,496,450],{"class":193},[70,498,245],{"class":114},[70,500,502,505,507],{"class":72,"line":501},7,[70,503,504],{"class":114},"half ",[70,506,150],{"class":110},[70,508,217],{"class":114},[70,510,512],{"class":72,"line":511},8,[70,513,141],{"emptyLinePlaceholder":140},[70,515,517],{"class":72,"line":516},9,[70,518,519],{"class":250},"# the cut is the open boundary of the half\n",[70,521,523,526,528,531],{"class":72,"line":522},10,[70,524,525],{"class":114},"cut ",[70,527,150],{"class":110},[70,529,530],{"class":114}," tf.boundary_paths(half).data   ",[70,532,533],{"class":250},"# point ids on the cut\n",[70,535,537,540,542],{"class":72,"line":536},11,[70,538,539],{"class":114},"from_cut ",[70,541,150],{"class":110},[70,543,544],{"class":114}," tf.geodesic_distances(half, cut)\n",[14,546,547],{},[51,548],{"alt":549,"src":550},"Distance from many seeds on the Stanford bunny: the bunny cut in half at mid-height, with every point on the cut as a seed. The half is colored by geodesic distance from the cut, teal at the cut to orange at the ear tips, with pink rings parallel to the cut and the cut itself as a thick pink line","\u002Fimg\u002Ftutorials\u002Fsteps\u002Ffast-geodesic-distances-2-seeds.png",[14,552,553],{},"Keep the top band. The bunny has holes in its base, so the top half has one boundary: the cut. The ids index the half's own points, so nothing maps back. The distance is zero on the cut and grows toward the ear tips.",[14,555,556],{},"One call handles all the seeds, here a few hundred. You do not loop over them. Isocontours of the field are curves parallel to the cut:",[61,558,560],{"className":101,"code":559,"language":103,"meta":66,"style":66},"levels = np.array([1.0, 2.0, 3.0], dtype=np.float32)\npaths, curve_points = tf.isocontours(half, from_cut, levels)\n",[32,561,562,593],{"__ignoreMap":66},[70,563,564,567,569,572,574,576,579,581,584,586,588,590],{"class":72,"line":73},[70,565,566],{"class":114},"levels ",[70,568,150],{"class":110},[70,570,571],{"class":114}," np.array([",[70,573,194],{"class":193},[70,575,197],{"class":114},[70,577,578],{"class":193},"2.0",[70,580,197],{"class":114},[70,582,583],{"class":193},"3.0",[70,585,294],{"class":114},[70,587,373],{"class":372},[70,589,150],{"class":110},[70,591,592],{"class":114},"np.float32)\n",[70,594,595,598,600],{"class":72,"line":124},[70,596,597],{"class":114},"paths, curve_points ",[70,599,150],{"class":110},[70,601,602],{"class":114}," tf.isocontours(half, from_cut, levels)\n",[56,604,606],{"id":605},"bounded-by-a-radius","Bounded by a radius",[14,608,609,610,613],{},"Often you only care about the neighborhood of a seed. Pass ",[32,611,612],{},"radius",". The front stops there.",[61,615,617],{"className":101,"code":616,"language":103,"meta":66,"style":66},"near = tf.geodesic_distances(mesh, [0], radius=0.5)\n\ninside = np.isfinite(near)\nregion = np.flatnonzero(inside)   # point ids within 0.5 of the seed\n",[32,618,619,641,645,655],{"__ignoreMap":66},[70,620,621,624,626,628,630,632,634,636,639],{"class":72,"line":73},[70,622,623],{"class":114},"near ",[70,625,150],{"class":110},[70,627,239],{"class":114},[70,629,242],{"class":193},[70,631,294],{"class":114},[70,633,612],{"class":372},[70,635,150],{"class":110},[70,637,638],{"class":193},"0.5",[70,640,208],{"class":114},[70,642,643],{"class":72,"line":124},[70,644,141],{"emptyLinePlaceholder":140},[70,646,647,650,652],{"class":72,"line":137},[70,648,649],{"class":114},"inside ",[70,651,150],{"class":110},[70,653,654],{"class":114}," np.isfinite(near)\n",[70,656,657,660,662,665],{"class":72,"line":144},[70,658,659],{"class":114},"region ",[70,661,150],{"class":110},[70,663,664],{"class":114}," np.flatnonzero(inside)   ",[70,666,667],{"class":250},"# point ids within 0.5 of the seed\n",[14,669,670],{},[51,671],{"alt":672,"src":673},"Bounded by a radius on the Stanford bunny: only points within geodesic distance 0.5 of the seed get a distance; the rest stay dark, and the pink ring marks the radius","\u002Fimg\u002Ftutorials\u002Fsteps\u002Ffast-geodesic-distances-3-radius.png",[14,675,676,677,680,681,684],{},"Points past the radius get ",[32,678,679],{},"inf",". So do points on a piece of the mesh the seed is not connected to, with or without a radius. Test with ",[32,682,683],{},"np.isfinite",", not with a comparison to a large number.",[56,686,688],{"id":687},"float32-or-float64","float32 or float64",[14,690,691],{},"The result has the mesh's dtype. A float32 mesh gives float32 distances. A float64 mesh gives float64 distances.",[61,693,695],{"className":101,"code":694,"language":103,"meta":66,"style":66},"mesh32 = tf.Mesh(faces, points.astype(np.float32))\nmesh64 = tf.Mesh(faces, points.astype(np.float64))\n\nd32 = tf.geodesic_distances(mesh32, [0])   # float32\nd64 = tf.geodesic_distances(mesh64, [0])   # float64\n",[32,696,697,707,717,721,739],{"__ignoreMap":66},[70,698,699,702,704],{"class":72,"line":73},[70,700,701],{"class":114},"mesh32 ",[70,703,150],{"class":110},[70,705,706],{"class":114}," tf.Mesh(faces, points.astype(np.float32))\n",[70,708,709,712,714],{"class":72,"line":124},[70,710,711],{"class":114},"mesh64 ",[70,713,150],{"class":110},[70,715,716],{"class":114}," tf.Mesh(faces, points.astype(np.float64))\n",[70,718,719],{"class":72,"line":137},[70,720,141],{"emptyLinePlaceholder":140},[70,722,723,726,728,731,733,736],{"class":72,"line":144},[70,724,725],{"class":114},"d32 ",[70,727,150],{"class":110},[70,729,730],{"class":114}," tf.geodesic_distances(mesh32, [",[70,732,242],{"class":193},[70,734,735],{"class":114},"])   ",[70,737,738],{"class":250},"# float32\n",[70,740,741,744,746,749,751,753],{"class":72,"line":385},[70,742,743],{"class":114},"d64 ",[70,745,150],{"class":110},[70,747,748],{"class":114}," tf.geodesic_distances(mesh64, [",[70,750,242],{"class":193},[70,752,735],{"class":114},[70,754,755],{"class":250},"# float64\n",[14,757,758,761],{},[32,759,760],{},"tf.read_stl"," and the mesh generators give float32 by default. The benchmark below ran in float32.",[14,763,764],{},"Distances are measured in the stored coordinates. A transformation set on the mesh does not change them.",[56,766,768],{"id":767},"working-with-results","Working with results",[14,770,771],{},"The distance field is a plain NumPy array, one value per point. Any scalar-field tool takes it.",[14,773,774,775,779],{},"Draw rings of equal distance with ",[18,776,778],{"href":777},"\u002Ftutorials\u002Fisocontours-on-a-triangle-mesh-in-python","isocontours",":",[61,781,783],{"className":101,"code":782,"language":103,"meta":66,"style":66},"levels = np.array([0.25, 0.5, 1.0], dtype=np.float32)\npaths, curve_points = tf.isocontours(mesh, d, levels)\n\nfor path_ids in paths:\n    ring = curve_points[path_ids]   # (n, 3) points along one ring\n",[32,784,785,812,821,825,839],{"__ignoreMap":66},[70,786,787,789,791,793,796,798,800,802,804,806,808,810],{"class":72,"line":73},[70,788,566],{"class":114},[70,790,150],{"class":110},[70,792,571],{"class":114},[70,794,795],{"class":193},"0.25",[70,797,197],{"class":114},[70,799,638],{"class":193},[70,801,197],{"class":114},[70,803,194],{"class":193},[70,805,294],{"class":114},[70,807,373],{"class":372},[70,809,150],{"class":110},[70,811,592],{"class":114},[70,813,814,816,818],{"class":72,"line":124},[70,815,597],{"class":114},[70,817,150],{"class":110},[70,819,820],{"class":114}," tf.isocontours(mesh, d, levels)\n",[70,822,823],{"class":72,"line":137},[70,824,141],{"emptyLinePlaceholder":140},[70,826,827,830,833,836],{"class":72,"line":144},[70,828,829],{"class":110},"for",[70,831,832],{"class":114}," path_ids ",[70,834,835],{"class":110},"in",[70,837,838],{"class":114}," paths:\n",[70,840,841,844,846,849],{"class":72,"line":385},[70,842,843],{"class":114},"    ring ",[70,845,150],{"class":110},[70,847,848],{"class":114}," curve_points[path_ids]   ",[70,850,851],{"class":250},"# (n, 3) points along one ring\n",[14,853,854],{},[51,855],{"alt":856,"src":857},"Working with results on the Stanford bunny: pink rings at distances 0.25, 0.5 and 1.0, and the patch within 0.5 of the seeds cut out with isobands in orange","\u002Fimg\u002Ftutorials\u002Fsteps\u002Ffast-geodesic-distances-4-patch.png",[14,859,860,861,864],{},"The level values must have the mesh's dtype. The paths do not come back in level order. If you need to know which ring is which, call ",[32,862,863],{},"tf.isocontours"," once per level.",[14,866,867],{},"Cut out the patch within a distance as its own mesh with isobands:",[61,869,871],{"className":101,"code":870,"language":103,"meta":66,"style":66},"(patch_faces, patch_points), labels, face_labels = tf.isobands(\n    mesh, d, np.array([0.5], dtype=np.float32), selected_bands=[0])\n\ntf.write_obj((patch_faces, patch_points), \"patch.obj\")\n",[32,872,873,883,909,913],{"__ignoreMap":66},[70,874,875,878,880],{"class":72,"line":73},[70,876,877],{"class":114},"(patch_faces, patch_points), labels, face_labels ",[70,879,150],{"class":110},[70,881,882],{"class":114}," tf.isobands(\n",[70,884,885,888,890,892,894,896,899,901,903,905,907],{"class":72,"line":124},[70,886,887],{"class":114},"    mesh, d, np.array([",[70,889,638],{"class":193},[70,891,294],{"class":114},[70,893,373],{"class":372},[70,895,150],{"class":110},[70,897,898],{"class":114},"np.float32), ",[70,900,489],{"class":372},[70,902,150],{"class":110},[70,904,494],{"class":114},[70,906,242],{"class":193},[70,908,245],{"class":114},[70,910,911],{"class":72,"line":137},[70,912,141],{"emptyLinePlaceholder":140},[70,914,915,918,921],{"class":72,"line":144},[70,916,917],{"class":114},"tf.write_obj((patch_faces, patch_points), ",[70,919,920],{"class":80},"\"patch.obj\"",[70,922,208],{"class":114},[14,924,925,926,929],{},"Band 0 is everything below 0.5. The patch boundary is cut exactly at the 0.5 ring. ",[32,927,928],{},"face_labels"," maps each patch face back to its source face.",[14,931,932,933,22,937,941],{},"The field also feeds the ",[18,934,936],{"href":935},"\u002Ftutorials\u002Fprincipal-curvatures-of-a-mesh-in-python","curvature",[18,938,940],{"href":939},"\u002Ftutorials\u002Ffast-mesh-booleans-in-python","boolean"," tools in the same library, so a whole pipeline stays in NumPy.",[56,943,945],{"id":944},"about-other-methods","About other methods",[14,947,948,949,951],{},"People search for the heat method, fast marching, or exact MMP geodesics. They all answer the same question: distance along the surface from seeds. ",[32,950,38],{}," runs a label-correcting front with a triangle-unfolding update. It is not the heat method. Our accuracy numbers below are measured against exact MMP distances.",[56,953,955],{"id":954},"related-tutorials","Related tutorials",[957,958,959,966,972,979],"ul",{},[960,961,962,965],"li",{},[18,963,964],{"href":777},"Fast and Robust Isocontours on a Triangle Mesh in Python"," — curves and bands of equal value on a scalar field.",[960,967,968,971],{},[18,969,970],{"href":935},"Fast and Robust Principal Curvatures of a Mesh in Python"," — curvature values and directions at every vertex.",[960,973,974,978],{},[18,975,977],{"href":976},"\u002Ftutorials\u002Fmesh-slicing-and-cross-sections-in-python","Fast and Robust Mesh Slicing and Cross-Sections in Python"," — plane sections, layers and slabs of a mesh.",[960,980,981,985],{},[18,982,984],{"href":983},"\u002Ftutorials\u002Ffast-closest-point-on-a-mesh-in-python","Fast and Robust Closest Point on a Mesh in Python"," — nearest surface point for a batch of queries.",[56,987,989],{"id":988},"performance","Performance",[14,991,992,993,996],{},"We measured 28 meshes from Thingi10K, from 10K to 3.2M faces, against MeshLib's ",[32,994,995],{},"computeSurfaceDistances",". Error is measured against exact MMP geodesics.",[998,999],"headline-numbers",{":items":1000},"[{\"value\":\"6.5×\",\"label\":\"Faster than MeshLib\",\"detail\":\"One seed, geometric mean, 28 meshes\"},{\"value\":\"9.2×\",\"label\":\"Faster than MeshLib\",\"detail\":\"32 seeds, geometric mean, 28 meshes\"},{\"value\":\"119ms\",\"label\":\"Geodesic distances\",\"detail\":\"3,154,110 faces, one seed\"}]",[14,1002,1003,1008,1009],{},[70,1004,1007],{"className":1005},[1006],"tag-pill","Apple M4 Max"," ",[70,1010,1012],{"className":1011},[1006],"16 threads",[1014,1015],"data-table",{":headers":1016,":highlight":450,":rows":1017},"[\"Meshes (geometric mean)\",\"trueform\",\"MeshLib\",\"Speedup\"]","[[\"10K–100K faces, one seed\",\"1.9 ms\",\"9.0 ms\",\"4.7×\"],[\"100K–1M faces, one seed\",\"8.1 ms\",\"63.3 ms\",\"7.8×\"],[\"1M–3.2M faces, one seed\",\"68.1 ms\",\"542 ms\",\"8.0×\"],[\"All 28 meshes, one seed\",\"8.9 ms\",\"58.2 ms\",\"6.5×\"],[\"10K–100K faces, 32 seeds\",\"1.3 ms\",\"9.1 ms\",\"7.3×\"],[\"100K–1M faces, 32 seeds\",\"6.6 ms\",\"67.6 ms\",\"10.3×\"],[\"1M–3.2M faces, 32 seeds\",\"55.4 ms\",\"597 ms\",\"10.8×\"],[\"All 28 meshes, 32 seeds\",\"6.7 ms\",\"61.7 ms\",\"9.2×\"]]",[14,1019,1020],{},"Error is the relative error per point against exact MMP distances, on the 22 meshes (up to 1.3M faces) small enough to have an exact reference. Each mesh's median error, averaged over the meshes, is 0.61 % from one seed and 0.2 % from 32 seeds. MeshLib's is 2.5 % and VTK's 9.3 % from one seed; PyMeshLab matches trueform's accuracy at 21× the time.",[14,1022,1023],{},[51,1024],{"alt":1025,"src":1026},"Benchmark chart: trueform against other Python libraries, geodesics","\u002Fimg\u002Falgorithms\u002Fbenchmark-geodesics-python-2026.png",[14,1028,1029,1033,1034],{},[18,1030,1032],{"href":1031},"\u002Ftrueform\u002Fbenchmarks","Full benchmarks"," · ",[18,1035,1038],{"href":1036,"rel":1037},"https:\u002F\u002Ftrueform.polydera.com\u002Fpy\u002Fmodules\u002Fgeometry#geodesic_distances",[92],"Documentation",[1040,1041],"cite-as",{"author":1042,"title":5},"Sajovic, {\\v{Z}}iga",[1044,1045,1046],"style",{},"html pre.shiki code .svObZ, html code.shiki .svObZ{--shiki-default:#B392F0}html pre.shiki code .sU2Wk, html code.shiki .sU2Wk{--shiki-default:#9ECBFF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html pre.shiki code .snl16, html code.shiki .snl16{--shiki-default:#F97583}html pre.shiki code .s95oV, html code.shiki .s95oV{--shiki-default:#E1E4E8}html pre.shiki code .sDLfK, html code.shiki .sDLfK{--shiki-default:#79B8FF}html pre.shiki code .sAwPA, html code.shiki .sAwPA{--shiki-default:#6A737D}html pre.shiki code .s9osk, html code.shiki .s9osk{--shiki-default:#FFAB70}",{"title":66,"searchDepth":124,"depth":124,"links":1048},[1049,1050,1051,1052,1053,1054,1055,1056,1057,1058],{"id":58,"depth":124,"text":59},{"id":97,"depth":124,"text":98},{"id":220,"depth":124,"text":221},{"id":395,"depth":124,"text":396},{"id":605,"depth":124,"text":606},{"id":687,"depth":124,"text":688},{"id":767,"depth":124,"text":768},{"id":944,"depth":124,"text":945},{"id":954,"depth":124,"text":955},{"id":988,"depth":124,"text":989},"2026-10-31","Compute geodesic distances on a triangle mesh in Python. Distance along the surface from one seed or many, bounded by a radius, in float32 or float64. One pip install, NumPy arrays in and out.","md",[1063,1064,1065,1066,1067,1068,1069,1070,1071,1072],"geodesic distance Python","geodesic distance mesh","surface distance triangle mesh","heat method geodesic Python","pygeodesic alternative","MeshLib geodesic alternative","PyMeshLab geodesic","libigl geodesic Python","potpourri3d alternative","numpy geodesic distance",{},"\u002Fimg\u002Fog\u002Ftutorials\u002Ffast-geodesic-distances-in-python.png","\u002Ftutorials\u002Ffast-geodesic-distances-in-python",{"title":5,"description":1060},"tutorials\u002Ffast-geodesic-distances-in-python",[103,1079,1080],"geodesics","tutorial","quf6iF0GVAG6c21WnyDsQa2H6jTXgUf1IU1jsmCgCYs",1793517812008]