Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scaling Transformation #1668

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading