Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.0 kB
2
Indexable
Never
#include <stdio.h>
#include <math.h>
#include <graphics.h>


void rotateClockwise(float *x, float *y, float angle) {
    float radians = angle * M_PI / 180.0;
    float newX = *x * cos(radians) + *y * sin(radians);
    float newY = -(*x) * sin(radians) + *y * cos(radians);
    *x = newX;
    *y = newY;
}

void rotateAnticlockwise(float *x, float *y, float angle) {
    float radians = angle * M_PI / 180.0;
    float newX = *x * cos(radians) - *y * sin(radians);
    float newY = *x * sin(radians) + *y * cos(radians);
    *x = newX;
    *y = newY;
}

int main() {
    int gd = DETECT, gm;
    initgraph(&gd, &gm, "");

    float angle = 45.0;
    int x1, y1, x2, y2, x3, y3;

    // Input vertices of the triangle
    printf("Enter coordinates of vertex A (x y): ");
    scanf("%d %d", &x1, &y1);

    printf("Enter coordinates of vertex B (x y): ");
    scanf("%d %d", &x2, &y2);

    printf("Enter coordinates of vertex C (x y): ");
    scanf("%d %d", &x3, &y3);

    
    setcolor(WHITE);
    line(x1, y1, x2, y2);
    line(x2, y2, x3, y3);
    line(x3, y3, x1, y1);

    
    float x1_float = x1, y1_float = y1;
    float x2_float = x2, y2_float = y2;
    float x3_float = x3, y3_float = y3;

    rotateClockwise(&x1_float, &y1_float, angle);
    rotateClockwise(&x2_float, &y2_float, angle);
    rotateClockwise(&x3_float, &y3_float, angle);

    
    setcolor(RED);
    line(x1_float, y1_float, x2_float, y2_float);
    line(x2_float, y2_float, x3_float, y3_float);
    line(x3_float, y3_float, x1_float, y1_float);

    rotateAnticlockwise(&x1_float, &y1_float, angle);
    rotateAnticlockwise(&x2_float, &y2_float, angle);
    rotateAnticlockwise(&x3_float, &y3_float, angle);

    
    setcolor(GREEN);
    line(x1_float, y1_float, x2_float, y2_float);
    line(x2_float, y2_float, x3_float, y3_float);
    line(x3_float, y3_float, x1_float, y1_float);

    getch();
    closegraph();
    return 0;
}
Leave a Comment