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

Create test3-2.py

parent 3c0a8e38
No related merge requests found
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)
print("Rectangular prism STL file 'prism.stl' has been generated.")
# Call the function to create the rectangular prism
create_rectangular_prism()
\ No newline at end of file
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