54 lines
1.8 KiB
Plaintext
54 lines
1.8 KiB
Plaintext
|
import bpy
|
||
|
import mathutils
|
||
|
|
||
|
def draw_plane(hessian):
|
||
|
# Extract the plane coefficients from the Hessian form
|
||
|
a, b, c, d = hessian
|
||
|
|
||
|
# Calculate the normal vector of the plane
|
||
|
normal = mathutils.Vector((a, b, c))
|
||
|
|
||
|
# Calculate the point at the center of the plane
|
||
|
point = normal * d
|
||
|
|
||
|
# Calculate a vector perpendicular to the normal
|
||
|
if abs(normal.z) < 1e-6:
|
||
|
tangent = mathutils.Vector((0, 0, 1))
|
||
|
else:
|
||
|
tangent = mathutils.Vector((0, 1, -normal.y/normal.z)).normalized()
|
||
|
|
||
|
binorm = tangent.cross(normal)
|
||
|
|
||
|
# Create a new mesh object for the point, dot, and line
|
||
|
mesh = bpy.data.meshes.new(name="Plane Center and Normal")
|
||
|
obj = bpy.data.objects.new(name="Plane Object", object_data=mesh)
|
||
|
|
||
|
# Create the vertices for the point, dot, and line
|
||
|
vertices = [
|
||
|
point + tangent * 0.1,
|
||
|
point,
|
||
|
point + normal,
|
||
|
point + binorm * 0.1,
|
||
|
]
|
||
|
|
||
|
# Create the edges for the line
|
||
|
edges = [
|
||
|
(0, 1), # Edge from point to start of line
|
||
|
(1, 2) , # Edge for the line
|
||
|
(1, 3)
|
||
|
]
|
||
|
|
||
|
# Create the mesh data for the point, dot, and line
|
||
|
mesh.from_pydata(vertices, edges, [])
|
||
|
|
||
|
# Add the object to the scene
|
||
|
bpy.context.scene.collection.objects.link(obj)
|
||
|
|
||
|
planes = [(-0.96225, 0.192449, 0.192451, -4.04145), (-0.404079, 0.888975, 0.21551, -3.85222), (-0.703526, -0.502519, -0.502519, -2.31159), (-0.123091, -0.86164, 0.492366, -2.33874), (-0.211079, -0.492518, 0.844317, -3.02547), (0.442326, 0.147442, 0.884652, -2.50651), (0.928279, -0.206284, 0.309426, -1.13456), (0.973329, -0.162221, 0.162222, -1.29777), (0.117041, 0.702247, -0.702247, -3.04307), (-9.6656e-08, 1.35319e-07, -1, -2)]
|
||
|
#planes = [(0, 0, -1, -12), (0, 1, 0, 9)]
|
||
|
|
||
|
for p in planes:
|
||
|
draw_plane(p)
|
||
|
|
||
|
#draw_plane((0, 1, 0, 11))
|
||
|
|