The 3D Rectangular Prism Viewer Web Application is designed to enable users to view and analyze 3D models of rectangular prisms. This application provides a seamless interface for retrieving, calculating, and visualizing 3D rectangular prisms using modern web technologies and CAD tools.
- Database Integration: Retrieves prism dimensions from a MySQL/PostgreSQL database.
- Calculation: Calculates the surface area and volume of the prisms.
- 3D Visualization: Displays a 3D CAD model using FreeCAD Python.
- Technology Stack: Backend developed with Django and Django REST Framework; frontend developed with React.
- Database Choice: The application supports both MySQL and PostgreSQL databases.
- Data Storage: The database stores the dimensions (length, width, height) of the rectangular prisms.
- Schema Design: A simple table schema with columns for
id
,length
,width
,height
, andtimestamp
.
- Django: Chosen for its robust ORM, scalability, and ease of integration with various databases.
- Django REST Framework (DRF): Used to build the RESTful API endpoints for retrieving and posting prism data.
- GET /prisms/: Retrieves a list of all rectangular prisms.
- GET /prisms/{id}/: Retrieves details of a specific prism by ID.
- POST /prisms/: Creates a new rectangular prism entry.
- PUT /prisms/{id}/: Updates an existing prism entry.
- DELETE /prisms/{id}/: Deletes a prism entry.
- Surface Area Calculation: The surface area (A) of a rectangular prism is calculated using the formula: [ A = 2(lw + lh + wh) ] where (l) is the length, (w) is the width, and (h) is the height.
- Volume Calculation: The volume (V) of a rectangular prism is calculated using the formula: [ V = l \times w \times h ]
- FreeCAD Python: Utilized to generate and render the 3D CAD models.
- CAD Model Generation: Based on the dimensions retrieved from the database, the application generates a 3D model of the prism.
- Rendering: The generated 3D model is rendered within the web application, allowing users to interact with and inspect the model.
- React: Chosen for its component-based architecture, allowing for a dynamic and responsive user interface.
- UI Components: Developed using React to display data and interact with the backend API.
- Data Display: Displays a list of all rectangular prisms with their dimensions.
- Model Interaction: Allows users to select a prism to view its detailed dimensions, surface area, volume, and 3D model.
- User Input: Provides forms for users to input new prism dimensions, which are then sent to the backend to create new entries.
WebRectangularPrismViewer/ ├── backend/ │ ├── manage.py # Django management script │ ├── rectangular_prism_app/ # Django application │ └── requirements.txt # Backend dependencies │ ├── frontend/ │ ├── package.json # Frontend dependencies │ ├── src/ # React source files │ └── public/ # Public files │ ├── cad/ │ ├── generate_prism.py # Script for generating CAD models with FreeCAD Python │ ├── prisms.sql # SQL file to initialize the database with sample data ├── README.md # Instructions and project overview
-
User Interaction:
- The user accesses the application through a web browser.
- The frontend displays a list of available prisms retrieved from the backend.
-
Data Retrieval:
- When a user selects a prism, the frontend sends a request to the backend API to retrieve the dimensions.
-
Calculation:
- The backend calculates the surface area and volume based on the retrieved dimensions.
-
3D Model Generation:
- Using FreeCAD Python, the backend generates a 3D CAD model of the selected prism.
- The 3D model is sent to the frontend for rendering.
-
Visualization:
- The frontend renders the 3D model, displaying it alongside the calculated surface area and volume.
- Users can interact with the 3D model, inspecting it from different angles and perspectives.
- Django Models:
from django.db import models class Prism(models.Model): length = models.FloatField() width = models.FloatField() height = models.FloatField() created_at = models.DateTimeField(auto_now_add=True)
Django REST Framework Serializers: from rest_framework import serializers from .models import Prism
class PrismSerializer(serializers.ModelSerializer): class Meta: model = Prism fields = 'all' Django REST Framework Views: from rest_framework import viewsets from .models import Prism from .serializers import PrismSerializer
class PrismViewSet(viewsets.ModelViewSet): queryset = Prism.objects.all() serializer_class = PrismSerializer URL Routing: from django.urls import path, include from rest_framework.routers import DefaultRouter from .views import PrismViewSet
router = DefaultRouter() router.register(r'prisms', PrismViewSet)
urlpatterns = [ path('', include(router.urls)), ] Frontend Implementation React Components:
PrismList: Displays a list of all prisms. PrismDetail: Shows detailed information and the 3D model of a selected prism. PrismForm: Allows users to input dimensions for a new prism. API Integration:
Using Axios or Fetch API to communicate with the Django REST API. 3D Model Rendering:
Integrating with a JavaScript library for rendering 3D models, such as Three.js, to display the FreeCAD-generated models. Conclusion The 3D Rectangular Prism Viewer Web Application is a comprehensive tool that combines robust backend data management, precise mathematical calculations, and advanced 3D visualization. By leveraging Django, Django REST Framework, React, and FreeCAD Python, the application provides an efficient and user-friendly platform for viewing and analyzing 3D rectangular prisms. This project demonstrates the integration of multiple technologies to create a cohesive and interactive user experience.