Mesh Isolines (3D)
1 min read•1 page
Instead of simple vertical height slicing, we can compute scalar values relative to a dynamic 3D attractor point. The distance from each mesh vertex to the attractor creates a spherical scalar field.
Distance Mapping:
1. Attractor Position: Move the attractor point in 3D space to shift the center of the scalar field. 2. Euclidean Distance: Every vertex receives a scalar value $f(v) = \|v - P_attractor\|$. 3. Concentric Slicing: Generating contours on this scalar field yields spherical rings around the attractor on the mesh.
python
1def assign_vertex_scalars(mesh, attractor_point):2 scalars = {}3 for v in mesh.vertices:4 # Compute Euclidean distance to 3D attractor point5 dx = v.x - attractor_point.x6 dy = v.y - attractor_point.y7 dz = v.z - attractor_point.z8 scalars[v.id] = math.sqrt(dx*dx + dy*dy + dz*dz)9 return scalars
Attractor X
0.00Attractor Z
0.003 min read•1 page
To generate the full isoline path, the algorithm processes each mesh triangle individually. We inspect the scalar values at the three corners, determine which edges cross the threshold, and compute linear intersections.
Intersection Cases:
1. Strict Bounds: An edge is crossed if the isovalue lies between the vertex values on that edge. 2. Segment Construction: A triangle can have 0, 1 (touches vertex exactly), or 2 edge crossings. If 2, we connect them into a contour line segment. 3. Boundary Continuity: Sharing edge vertex coordinates guarantees that segments link together into continuous closed paths.
python
1def slice_mesh_triangle(v0, v1, v2, s0, s1, s2, isovalue):2 # Track intersection coordinates3 points = []45 # Check Edge 0-16 if (s0 <= isovalue <= s1) or (s1 <= isovalue <= s0) and s0 != s1:7 t = (isovalue - s0) / (s1 - s0)8 points.append(v0 + t * (v1 - v0))910 # Check Edge 1-211 if (s1 <= isovalue <= s2) or (s2 <= isovalue <= s1) and s1 != s2:12 t = (isovalue - s1) / (s2 - s1)13 points.append(v1 + t * (v2 - v1))1415 # Check Edge 2-016 if (s2 <= isovalue <= s0) or (s0 <= isovalue <= s2) and s2 != s0:17 t = (isovalue - s2) / (s0 - s2)18 points.append(v2 + t * (v0 - v2))1920 return points if len(points) == 2 else None
Slicing Isovalue Z
0.002 min read•1 page
By calculating the Euclidean distance from every vertex to a dynamic 3D attractor, we obtain a distance field. Slicing the mesh at specific distance thresholds (isovalues) draws continuous concentric isolines representing equal-distance bands on the surface.
Distance Contours:
1. Attractor Field: Computes distance scalars at each vertex relative to the attractor sphere. 2. Segment Intersections: Triangles crossing a target distance isovalue receive an isoline segment. 3. Concentric Rings: Renders nested rings that curve perfectly along the peaks and valleys of the terrain mesh.
python
1def generate_distance_isolines(mesh, attractor_pt, levels):2 all_contours = []3 for isovalue in levels:4 segments = []5 for face in mesh.faces:6 # 1. Compute distance to attractor for each vertex7 s0 = distance(face.v0.position, attractor_pt)8 s1 = distance(face.v1.position, attractor_pt)9 s2 = distance(face.v2.position, attractor_pt)1011 # 2. Slice the triangle using these distance scalars12 pts = slice_mesh_triangle(13 face.v0, face.v1, face.v2,14 s0, s1, s2,15 isovalue16 )17 if pts:18 segments.append(pts)19 all_contours.append(segments)20 return all_contours
Attractor X
0.00Attractor Z
0.00Distance Contours Count
8.00