0% found this document useful (0 votes)
57 views4 pages

Tugas 4: Source Code

This C++ source code defines functions to draw two lines (AB and CD) and find their point of intersection. It initializes variables for the x and y coordinates of points A, B, C and D. It then calculates the slopes (MAB and MCD) and y-intercepts (CAB and CCD) of the two lines. The point of intersection (titik_X, titik_Y) is calculated using the slopes and y-intercepts. The main function sets up the OpenGL window and calls the garis function to draw the lines and intersection point.

Uploaded by

Ajik Baskara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views4 pages

Tugas 4: Source Code

This C++ source code defines functions to draw two lines (AB and CD) and find their point of intersection. It initializes variables for the x and y coordinates of points A, B, C and D. It then calculates the slopes (MAB and MCD) and y-intercepts (CAB and CCD) of the two lines. The point of intersection (titik_X, titik_Y) is calculated using the slopes and y-intercepts. The main function sets up the OpenGL window and calls the garis function to draw the lines and intersection point.

Uploaded by

Ajik Baskara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Jane Christine - 672017100

Sukma Aji Baskara - 672017107

Grafika Komputer – IN232D

TUGAS 4

Source Code

//Sukma Aji Baskara 672017107


//Jane Christine 672017100

#include <windows.h>
#include <gl/Gl.h>
#include <gl/glut.h>

float xA = 200, yA = 50;


float xB = 450, yB = 475;
float xC = 125, yC = 300;
float xD = 450, yD = 175;
float MAB, MCD, CAB, CCD, titik_X, titik_Y;

void garis(void)
{
MAB = (yB - yA) / (xB - xA);
CAB = yA - (MAB * xA);

MCD = (yD - yC) / (xD - xC);


CCD = yC - (MCD * xC);

titik_X = (CCD - CAB) / (MAB - MCD);


titik_Y = (MAB * titik_X) + CAB;

glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINES);
//GARIS AB
glColor3f(0, 0, 1);
glVertex2i(xA, yA);
glVertex2i(xB, yB);
//GARIS CD
glColor3f(0, 1, 0);
glVertex2i(xC, yC);
glVertex2i(xD, yD);
glEnd();
glFlush();

//TITIK POTONG
glBegin(GL_POINTS);
glColor3f(1, 0, 0);
glVertex2i(titik_X, titik_Y);
glEnd();
glFlush();
}

void display(void) {
glClearColor(1, 1, 1, 0);
glColor3f(0.0f, 0.0f, 0.0f);
glPointSize(6.0);
glLineWidth(4.0);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 640, 0, 480);
glFlush();

int main(int x, char** y) {


glutInit(&x, y);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(200, 200);
glutCreateWindow("672017107_tugas4");
glutDisplayFunc(garis);
display();
glutMainLoop();
}

Perhitungan
MAB = (475 - 50) / (450 - 200)
= 1,7
CAB = 50 - (1,7 * 200)
= -290

MCD = (175 - 300) / (450 - 125)


= -0,38
CCD = 300 - ( -0,38 * 125)
= 347,5

titik_X = (347,5 - (-290)) / (1,7 - (-0,38)


= 306,49
titik_Y = (MAB * titik_X) + CAB

You might also like