Visualize a 3D scalar field
- Peter Mortier
- Oct 28, 2024
- 1 min read
Updated: 6 days ago
This example demonstrates how to use HelloTriangle to visualize a 3D scalar field on a mesh (in this case a triangulated surface).
Visualizing scalar fields on 3D models is a common task in engineering and scientific research. This technique can be applied to visualize temperature distribution, stress analysis, or elevation data on models of terrains. Additionally, it is often used to compute and display the difference between two surfaces, such as the deviation between a manufactured part and its design model.
In this example, we use the famous Stanford bunny, to illustrate how to compute and visualize the distance of each vertex from a fixed point in 3D space. The scalar field is interpolated across the mesh, creating a smooth visualization that highlights regions closer or farther from the point.
# import Stanford bunny
bunny = Mesh.read('bunny.stl')
# compute distance from a point in 3D space
dist = bunny.distanceFromPoint([-40.0, 0.0, 20.0])
# add node field called 'distance'
bunny.addField('node', dist, 'distance')
# draw bunny with 3D scalar field
draw(bunny, field = 'distance')
