Skip to content
Snippets Groups Projects
Commit 77ecf9b5 authored by Fabian's avatar Fabian
Browse files

Create test3.py

parent ddef1e1e
Branches
No related merge requests found
test3.py 0 → 100644
import pythreejs as three
from IPython.display import display
def create_rectangular_prism():
# Prompt for the dimensions of the rectangular prism
length = float(input("Enter the length of the prism: "))
width = float(input("Enter the width of the prism: "))
height = float(input("Enter the height of the prism: "))
# Create the STL code for the rectangular prism
stl_code = f'solid prism\n'
# Front face
stl_code += f'facet normal 0 0 -1\n'
stl_code += f' outer loop\n'
stl_code += f' vertex 0 0 0\n'
stl_code += f' vertex {length} 0 0\n'
stl_code += f' vertex {length} {width} 0\n'
stl_code += f' endloop\n'
stl_code += f'endfacet\n'
# Back face
stl_code += f'facet normal 0 0 1\n'
stl_code += f' outer loop\n'
stl_code += f' vertex 0 {width} {height}\n'
stl_code += f' vertex {length} {width} {height}\n'
stl_code += f' vertex {length} 0 {height}\n'
stl_code += f' endloop\n'
stl_code += f'endfacet\n'
# Right face
stl_code += f'facet normal 1 0 0\n'
stl_code += f' outer loop\n'
stl_code += f' vertex {length} 0 0\n'
stl_code += f' vertex {length} {width} 0\n'
stl_code += f' vertex {length} {width} {height}\n'
stl_code += f' endloop\n'
stl_code += f'endfacet\n'
# Left face
stl_code += f'facet normal -1 0 0\n'
stl_code += f' outer loop\n'
stl_code += f' vertex 0 {width} {height}\n'
stl_code += f' vertex 0 0 {height}\n'
stl_code += f' vertex 0 0 0\n'
stl_code += f' endloop\n'
stl_code += f'endfacet\n'
# Top face
stl_code += f'facet normal 0 1 0\n'
stl_code += f' outer loop\n'
stl_code += f' vertex 0 {width} {height}\n'
stl_code += f' vertex {length} {width} {height}\n'
stl_code += f' vertex {length} {width} 0\n'
stl_code += f' endloop\n'
stl_code += f'endfacet\n'
# Bottom face
stl_code += f'facet normal 0 -1 0\n'
stl_code += f' outer loop\n'
stl_code += f' vertex 0 0 0\n'
stl_code += f' vertex {length} 0 0\n'
stl_code += f' vertex {length} 0 {height}\n'
stl_code += f' endloop\n'
stl_code += f'endfacet\n'
stl_code += f'endsolid prism\n'
# Write the STL code to a file
with open('prism.stl', 'w') as file:
file.write(stl_code)
# Create the rectangular prism geometry
geometry = three.BoxGeometry(length=length, width=width, height=height)
# Create the material and mesh
material = three.MeshBasicMaterial(color='lightblue', side='DoubleSide')
mesh = three.Mesh(geometry=geometry, material=material)
# Create the scene and add the mesh
scene = three.Scene()
scene.add(mesh)
# Create the camera and renderer
camera = three.PerspectiveCamera(position=[10, 10, 10], aspect=1)
renderer = three.Renderer(camera=camera, scene=scene, controls=[three.OrbitControls(controlling=camera)])
# Render the scene
display(renderer)
# Call the function to create the rectangular prism and generate the image
create_rectangular_prism()
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment