-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1668 from Arushi2S/Arushi2S-patch-5
Scaling Transformation
- Loading branch information
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
Geometric Transformation Algorithm/Scaling Transformation/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# README for 3D Scaling Program | ||
|
||
This project implements a 3D scaling transformation in C. The program allows the user to input a 3D point and apply scaling factors along the X, Y, and Z axes, resizing the point's coordinates accordingly. | ||
|
||
## Process | ||
|
||
### User Input: | ||
1. The user is prompted to enter the coordinates of the point in 3D: `(x, y, z)`. | ||
2. The user specifies scaling factors for each axis: `scaleX`, `scaleY`, and `scaleZ`. | ||
|
||
### Scaling Calculation: | ||
The program applies the scaling transformation to the input point using the following formulas: | ||
|
||
```c | ||
x_scaled = x * scaleX; | ||
y_scaled = y * scaleY; | ||
z_scaled = z * scaleZ; | ||
``` | ||
|
||
### Output: | ||
The program prints the new coordinates of the point after applying the scaling transformation. | ||
|
||
## Example Run | ||
|
||
**Input:** | ||
|
||
Enter the coordinates of the point (x y z): 2 3 4 | ||
Enter the scaling factors (scaleX scaleY scaleZ): 1.5 2.0 0.5 | ||
|
||
**Output:** | ||
|
||
Scaled coordinates: (3.00, 6.00, 2.00) | ||
|
||
## Complexity Analysis | ||
|
||
- **Time Complexity:** O(1) | ||
The program performs a constant number of operations regardless of input size. | ||
|
||
- **Space Complexity:** O(1) | ||
Only basic variables are used for coordinates and calculations, so no additional memory allocation is required. | ||
|
||
## Assumptions | ||
|
||
- The program assumes valid numeric input for the coordinates and scaling factors. | ||
- Each scaling factor affects only its respective axis. |
28 changes: 28 additions & 0 deletions
28
Geometric Transformation Algorithm/Scaling Transformation/program.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <stdio.h> | ||
|
||
void scale3D(float x, float y, float z, float scaleX, float scaleY, float scaleZ, float *x_scaled, float *y_scaled, float *z_scaled) { | ||
*x_scaled = x * scaleX; | ||
*y_scaled = y * scaleY; | ||
*z_scaled = z * scaleZ; | ||
} | ||
|
||
int main() { | ||
float x, y, z; // Original coordinates | ||
float scaleX, scaleY, scaleZ; // Scaling factors | ||
float x_scaled, y_scaled, z_scaled; | ||
|
||
// Taking user input | ||
printf("Enter the coordinates (x, y, z): "); | ||
scanf("%f %f %f", &x, &y, &z); | ||
|
||
printf("Enter the scaling factors (scaleX, scaleY, scaleZ): "); | ||
scanf("%f %f %f", &scaleX, &scaleY, &scaleZ); | ||
|
||
// Applying scaling transformation | ||
scale3D(x, y, z, scaleX, scaleY, scaleZ, &x_scaled, &y_scaled, &z_scaled); | ||
|
||
// Displaying the result | ||
printf("Scaled coordinates: (%.2f, %.2f, %.2f)\n", x_scaled, y_scaled, z_scaled); | ||
|
||
return 0; | ||
} |