C and C++ Computer Graphics

Program for 3D scaling

In computer graphics, 3D scaling is a geometric transformation used to resize objects in three-dimensional space. By applying scaling factors along the x-axis, y-axis, and z-axis, we can enlarge or shrink the size of a 3D object without altering its overall shape. Scaling is one of the most fundamental 3D transformations, along with translation, rotation, and reflection.

Scaling plays an important role in 3D modeling, animations, gaming, simulations, and CAD applications, where objects need to be proportionally adjusted.

Mathematical Representation of 3D Scaling

The scaling transformation for a point (π‘₯,𝑦,𝑧) in 3D is given by:

xβ€² = xΓ—Sx ​
𝑦′ = 𝑦 ×𝑆𝑦
𝑧′ = 𝑧 Γ— 𝑆𝑧

#include 

int main() {
    float x, y, z;
    float sx, sy, sz;
    float x_new, y_new, z_new;

    // Input original coordinates
    printf("Enter the coordinates of the point (x, y, z): ");
    scanf("%f %f %f", &x, &y, &z);

    // Input scaling factors
    printf("Enter scaling factors (sx, sy, sz): ");
    scanf("%f %f %f", &sx, &sy, &sz);

    // Apply scaling transformation
    x_new = x * sx;
    y_new = y * sy;
    z_new = z * sz;

    // Output result
    printf("Original Point: (%.2f, %.2f, %.2f)\n", x, y, z);
    printf("After Scaling:  (%.2f, %.2f, %.2f)\n", x_new, y_new, z_new);

    return 0;
}
​

Leave a comment

Your email address will not be published. Required fields are marked *