Skip to content

Commit

Permalink
Merge pull request #1668 from Arushi2S/Arushi2S-patch-5
Browse files Browse the repository at this point in the history
Scaling Transformation
  • Loading branch information
pankaj-bind authored Nov 5, 2024
2 parents 36873e9 + ebda20f commit 0aede57
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
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.
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;
}

0 comments on commit 0aede57

Please sign in to comment.