diff --git a/Geometric Transformation Algorithm/Scaling Transformation/README.md b/Geometric Transformation Algorithm/Scaling Transformation/README.md new file mode 100644 index 00000000..56edad16 --- /dev/null +++ b/Geometric Transformation Algorithm/Scaling Transformation/README.md @@ -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. diff --git a/Geometric Transformation Algorithm/Scaling Transformation/program.c b/Geometric Transformation Algorithm/Scaling Transformation/program.c new file mode 100644 index 00000000..872f9d6e --- /dev/null +++ b/Geometric Transformation Algorithm/Scaling Transformation/program.c @@ -0,0 +1,28 @@ +#include + +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; +}