#include #include #include #include using namespace std; #define pi 3.14 #define T - 6 * pi / 180 #define alpha pi / 8 //#define th pi / 180 int a, b, xmin, xmax, ymin, y : Notes">

NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include "graphics.h"
#include <math.h>
#include <stdlib.h>
#include <dos.h>
#include <windows.h>
#include <iostream>

using namespace std;

#define pi 3.14
#define T - 6 * pi / 180
#define alpha pi / 8
//#define th pi / 180

int a, b, xmin, xmax, ymin, ymax;




int xe(float x) {
return ((int)floor((x - xmin) / (xmax - xmin)*a));
}

int ye(float y) {
return ((int)floor((ymax - y) / (ymax - ymin)*b));
}

void xoy() {
line(xe(xmin), ye(0), xe(xmax), ye(0));
line(xe(0), ye(ymin), xe(0), ye(xmax));
}

void triunghi() {
setcolor(GREEN);
line(xe(0), ye(-150), xe(-150), ye(80));
line(xe(-150), ye(80), xe(150), ye(80));
line(xe(150), ye(80), xe(0), ye(-150));
/*setcolor(RED);
outtextxy(xe(-5), ye(-170), "A");
outtextxy(xe(-160), ye(80), "B");
outtextxy(xe(150), ye(80), "C");*/
}



/*void trans() {
setcolor(YELLOW);
int xt = 100;
int yt = 100;
line(xe(0 + xt), ye(-150 + yt), xe(-150 + xt), ye(80 + yt));
line(xe(-150 + xt), ye(80 +yt), xe(150 + xt), ye(80 + yt));
line(xe(150 + xt), ye(80 + yt), xe(0 + xt), ye(-150 + yt));
setcolor(BLUE);
outtextxy(xe(-5 + xt), ye(-170 + yt), "A");
outtextxy(xe(-160 + xt), ye(80 + yt), "B");
outtextxy(xe(150 + xt), ye(80 + yt), "C");
}*/

/*void scale() {
setcolor(12);
int xs = 2, ys = 2;
line(xe(0 * xs), ye(-150 * ys), xe(-150 * xs), ye(80 * ys));
line(xe(-150 * xs), ye(80 * ys), xe(150 * xs), ye(80 * ys));
line(xe(150 * xs), ye(80 * ys), xe(0 * xs), ye(-150 * ys));
setcolor(14);
outtextxy(xe(-5 * xs), ye(-170 * ys), "A");
outtextxy(xe(-160 * xs), ye(80 * ys), "B");
outtextxy(xe(150 * xs), ye(80 * ys), "C");
}*/

/*void spin() {
float xa = 0;
float ya = -150;
float xb = -150;
float yb = 80;
float xc = 150;
float yc = 80;

float a1, a2, b1, b2, c1, c2;

for (int i = 0; i < 60; i++) {
cleardevice();

setcolor(YELLOW);

line(xe(xa), ye(ya), xe(xb), ye(yb));
line(xe(xb), ye(yb), xe(xc), ye(yc));
line(xe(xc), ye(yc), xe(xa), ye(ya));

delay(500);

xa = xa * cos(T) - ya * sin(T);
ya = xa * sin(T) + ya* cos(T);

xb = xb * cos(T) - yb * sin(T);
yb = xb * sin(T) + yb* cos(T);

xc = xc * cos(T) - yc * sin(T);
yc = xc * sin(T) + yc* cos(T);
}
}*/

/*void xoyoz() {
line(xe(0), ye(0), xe(0), ye(ymax));
line(xe(0), ye(0), xe(xmax), ye(0));
line(xe(0), ye(0), xe(xmin * cos(alpha)), ye(xmin * sin(alpha)));
}*/

struct Punct2D {
float x, y;
Punct2D(float x = 0, float y = 0) {
this->x = x;
this->y = y;
}
};
/*
struct Punct3D {
float x, y, z;
Punct3D(float x = 0, float y = 0, float z = 0) {
this->x = x;
this->y = y;
this->z = z;
}
};

Punct2D transfPunct(Punct3D punct) {
float xprim = xe(punct.x - punct.y * cos(alpha));
float yprim = ye(punct.z - punct.y * sin(alpha));

Punct2D punctNou = Punct2D();
punctNou.x = xprim;
punctNou.y = yprim;

return punctNou;
}

Punct3D piramida3d[5];
*/


void init() {
initwindow(800, 600);
a = getmaxx();
b = getmaxy();
xmin = (int)(-a / 2);
xmax = (int)(a / 2);
ymin = (int)(-b / 2);
ymax = (int)(b / 2);

/*piramida3d[0] = Punct3D(50, 50, 0);
piramida3d[1] = Punct3D(250, 50, 0);
piramida3d[2] = Punct3D(250, 250, 0);
piramida3d[3] = Punct3D(50, 250, 0);
piramida3d[4] = Punct3D(150, 150, 250);*/
}

/*
void deseneazaPiramida() {

Punct2D piramida2d[5];

for (int i = 0; i < 5; i++) {
piramida2d[i] = transfPunct(piramida3d[i]);
}

setcolor(RED);
line(piramida2d[0].x, piramida2d[0].y, piramida2d[1].x, piramida2d[1].y);
line(piramida2d[1].x, piramida2d[1].y, piramida2d[2].x, piramida2d[2].y);
line(piramida2d[2].x, piramida2d[2].y, piramida2d[3].x, piramida2d[3].y);
line(piramida2d[3].x, piramida2d[3].y, piramida2d[0].x, piramida2d[0].y);
line(piramida2d[4].x, piramida2d[4].y, piramida2d[0].x, piramida2d[0].y);
line(piramida2d[4].x, piramida2d[4].y, piramida2d[1].x, piramida2d[1].y);
line(piramida2d[4].x, piramida2d[4].y, piramida2d[2].x, piramida2d[2].y);
line(piramida2d[4].x, piramida2d[4].y, piramida2d[3].x, piramida2d[3].y);
}

void transPiramida() {

Punct2D piramida2d[5];

for (int i = 0; i < 5; i++) {
piramida2d[i] = transfPunct(piramida3d[i]);
}

setcolor(YELLOW);
line(piramida2d[0].x + 100, piramida2d[0].y + 100, piramida2d[1].x + 100, piramida2d[1].y + 100);
line(piramida2d[1].x + 100, piramida2d[1].y + 100, piramida2d[2].x + 100, piramida2d[2].y + 100);
line(piramida2d[2].x + 100, piramida2d[2].y + 100, piramida2d[3].x + 100, piramida2d[3].y + 100);
line(piramida2d[3].x + 100, piramida2d[3].y + 100, piramida2d[0].x + 100, piramida2d[0].y + 100);
line(piramida2d[4].x + 100, piramida2d[4].y + 100, piramida2d[0].x + 100, piramida2d[0].y + 100);
line(piramida2d[4].x + 100, piramida2d[4].y + 100, piramida2d[1].x + 100, piramida2d[1].y + 100);
line(piramida2d[4].x + 100, piramida2d[4].y + 100, piramida2d[2].x + 100, piramida2d[2].y + 100);
line(piramida2d[4].x + 100, piramida2d[4].y + 100, piramida2d[3].x + 100, piramida2d[3].y + 100);
}

void zoomInPiramida() {

Punct2D piramida2d[5];

for (int i = 0; i < 5; i++) {
piramida2d[i] = transfPunct(piramida3d[i]);
}

setcolor(BLUE);
line(piramida2d[0].x * 1.2, piramida2d[0].y * 1.2, piramida2d[1].x * 1.2, piramida2d[1].y * 1.2);
line(piramida2d[1].x * 1.2, piramida2d[1].y * 1.2, piramida2d[2].x * 1.2, piramida2d[2].y * 1.2);
line(piramida2d[2].x * 1.2, piramida2d[2].y * 1.2, piramida2d[3].x * 1.2, piramida2d[3].y * 1.2);
line(piramida2d[3].x * 1.2, piramida2d[3].y * 1.2, piramida2d[0].x * 1.2, piramida2d[0].y * 1.2);
line(piramida2d[4].x * 1.2, piramida2d[4].y * 1.2, piramida2d[0].x * 1.2, piramida2d[0].y * 1.2);
line(piramida2d[4].x * 1.2, piramida2d[4].y * 1.2, piramida2d[1].x * 1.2, piramida2d[1].y * 1.2);
line(piramida2d[4].x * 1.2, piramida2d[4].y * 1.2, piramida2d[2].x * 1.2, piramida2d[2].y * 1.2);
line(piramida2d[4].x * 1.2, piramida2d[4].y * 1.2, piramida2d[3].x * 1.2, piramida2d[3].y * 1.2);
}

void zoomOutPiramida() {

Punct2D piramida2d[5];

for (int i = 0; i < 5; i++) {
piramida2d[i] = transfPunct(piramida3d[i]);
}

setcolor(GREEN);
line(piramida2d[0].x * 0.75, piramida2d[0].y * 0.75, piramida2d[1].x * 0.75, piramida2d[1].y * 0.75);
line(piramida2d[1].x * 0.75, piramida2d[1].y * 0.75, piramida2d[2].x * 0.75, piramida2d[2].y * 0.75);
line(piramida2d[2].x * 0.75, piramida2d[2].y * 0.75, piramida2d[3].x * 0.75, piramida2d[3].y * 0.75);
line(piramida2d[3].x * 0.75, piramida2d[3].y * 0.75, piramida2d[0].x * 0.75, piramida2d[0].y * 0.75);
line(piramida2d[4].x * 0.75, piramida2d[4].y * 0.75, piramida2d[0].x * 0.75, piramida2d[0].y * 0.75);
line(piramida2d[4].x * 0.75, piramida2d[4].y * 0.75, piramida2d[1].x * 0.75, piramida2d[1].y * 0.75);
line(piramida2d[4].x * 0.75, piramida2d[4].y * 0.75, piramida2d[2].x * 0.75, piramida2d[2].y * 0.75);
line(piramida2d[4].x * 0.75, piramida2d[4].y * 0.75, piramida2d[3].x * 0.75, piramida2d[3].y * 0.75);

}



void spinPiramida() {
float th = 3.14 / 180;
int tip_rotatie = 2;
for (int i = 0; i < 360; i++) {
for (int j = 0; j < 5; j++) {
switch (tip_rotatie) {
case 1:
piramida3d[j].x = piramida3d[j].x;
piramida3d[j].y = piramida3d[j].y * cos(th) - piramida3d[j].z * sin(th);
piramida3d[j].z = piramida3d[j].y * sin(th) + piramida3d[j].z * cos(th);
break;
case 2:
piramida3d[j].x = piramida3d[j].x * cos(th) - piramida3d[j].y * sin(th);
piramida3d[j].y = piramida3d[j].x * sin(th) + piramida3d[j].y * cos(th);
piramida3d[j].z = piramida3d[j].z;
break;
default:
piramida3d[j].x = piramida3d[j].x * cos(th) - piramida3d[j].z * sin(th);
piramida3d[j].y = piramida3d[j].y;
piramida3d[j].z = piramida3d[j].x * sin(th) + piramida3d[j].z * cos(th);
}
cleardevice();
xoyoz();
deseneazaPiramida();
delay(100);
}
}
}

Punct3D punct[3000];


void deseneazaSpirala() {
float t = 0;
int index = 0;
float h = pi / 10, x, y, z;
while (t <= 100) {
x = t * cos(t / 4);
y = t * sin(t / 4);
z = t;
punct[index] = Punct3D(x, y, z);
index++;
t += h;
}
Punct2D punct2d[3000];
for (int i = 0; i < index; i++) {
punct2d[i] = transfPunct(punct[i]);
putpixel(punct2d[i].x, punct2d[i].y, YELLOW);
}
}

void spinSpirala() {
float th = -2 * 3.14 / 180;
int tip_rotatie = 2;
for (int i = 0; i < 160; i++) {
for (int j = 0; j < 5; j++) {
switch (tip_rotatie) {
case 1:
punct[j].x = punct[j].x;
punct[j].y = punct[j].y * cos(th) - punct[j].z * sin(th);
punct[j].z = punct[j].y * sin(th) + punct[j].z * cos(th);
break;
case 2:
punct[j].x = punct[j].x * cos(th) - punct[j].y * sin(th);
punct[j].y = punct[j].x * sin(th) + punct[j].y * cos(th);
punct[j].z = piramida3d[j].z;
break;
default:
punct[j].x = punct[j].x * cos(th) - punct[j].z * sin(th);
punct[j].y = punct[j].y;
punct[j].z = punct[j].x * sin(th) + punct[j].z * cos(th);
}
cleardevice();
xoyoz();
deseneazaSpirala();
delay(10);
}
}
}
*/

void colineare(Punct2D p, Punct2D q, Punct2D r) {
if ((q.y - p.y)*(r.x - q.x) - (q.x - p.x)*(r.y - q.y) == 0)
cout << "Coliniare!";
else
cout << "Necoliniare!";
}

void distantare(Punct2D a, Punct2D b) {
float t1 = b.x - a.x;
float t2 = b.y - a.y;
float dist = sqrt(t1 *t1 + t2*t2);
printf(" Distanta dintre <%.2f;%.2f> si <%.2f;%.2f> este %.2f pct.n", a.x, a.y, b.x, b.y, dist);
}

void triunghi_coliniar(Punct2D p, Punct2D q, Punct2D r) {
setcolor(GREEN);
line(xe(p.x), ye(p.y), xe(q.x), ye(q.y));
line(xe(r.x), ye(r.y), xe(q.x), ye(q.y));
line(xe(p.x), ye(p.y), xe(r.x), ye(r.y));

distantare(p, q);
distantare(r, q);
distantare(p, r);

colineare(p, q, r);;
}

float verif_triunghi_coliniar(Punct2D a, Punct2D b, Punct2D c) {
return (a.x*b.y) + (a.y*c.x)*(b.x*c.y) - (b.y*c.x) - (b.y*a.x) - (a.y*b.x);
/*
==0 - pe segment
<0 - planul stang
>0 - planul drept
*/
}

void apartine_triunghi(Punct2D p, Punct2D q, Punct2D r, Punct2D k){
float a1, a2, a3;
a1 = verif_triunghi_coliniar(p, q, k);
a2 = verif_triunghi_coliniar(p, r, k);
a3 = verif_triunghi_coliniar(q, r, k);

if (a1 == 0 && a2 == 0 && a3 == 0)
printf(" Punctele <%.2f;%.2f>, <%.2f;%.2f> si <%.2f;%.2f> sunt colinare.n",
p.x, p.y, q.x, q.y, r.x, r.y);
if (a1 < 0 && a2 < 0 && a3 < 0)
printf(" Punctul <%.2f;%.2f> este interior triunghiului.n",
k.x, k.y);
if (a1 > 0 && a2 > 0 && a3 > 0)
printf(" Punctul <%.2f;%.2f> este exterir triunghiului.n",
k.x, k.y);
setcolor(YELLOW);
circle(xe(k.x), ye(k.y), 5);
setcolor(LIGHTGRAY);
line(xe(p.x), ye(p.y), xe(k.x), ye(k.y));
line(xe(q.x), ye(q.y), xe(k.x), ye(k.y));
line(xe(r.x), ye(r.y), xe(k.x), ye(k.y));
putpixel(xe(k.x), ye(k.y), LIGHTRED);

}

void seg_intersect(Punct2D a, Punct2D b, Punct2D c, Punct2D d) {
if (verif_triunghi_coliniar(a, b, c) *verif_triunghi_coliniar(a, b, d) <= 0 &&
verif_triunghi_coliniar(c, d, a) *verif_triunghi_coliniar(c, d, b))
cout << "Se intersecteaza";
else
cout << "Nu se intersecteaza";

setcolor(LIGHTGRAY);
line(xe(a.x), ye(a.y), xe(b.x), ye(b.y));
line(xe(c.x), ye(c.y), xe(d.x), ye(d.y));
setcolor(DARKGRAY);
circle(xe(a.x), ye(a.y), 5);
circle(xe(b.x), ye(b.y), 5);
circle(xe(c.x), ye(c.y), 5);
circle(xe(d.x), ye(d.y), 5);
putpixel(xe(a.x), ye(a.y), LIGHTRED);
putpixel(xe(b.x), ye(b.y), LIGHTRED);
putpixel(xe(c.x), ye(c.y), LIGHTRED);
putpixel(xe(d.x), ye(d.y), LIGHTRED);
}

float produss(Punct2D A, Punct2D B) {
return A.x*B.x + A.y*B.y;
}
float cosin(Punct2D A, Punct2D B) {
return produss
}

void main() {
init();
xoy();

/*Punct3D p;
p.x = 100, p.y = 92, p.z = 40;
Punct2D pt;
pt = transfPunct(p);
putpixel(pt.x, pt.y, RED);

deseneazaPiramida();
transPiramida();
zoomInPiramida();
zoomOutPiramida();

spinPiramida();

deseneazaSpirala();
spinSpirala();*/


Punct2D p(10, 20),q(20, 200),r(300,60),k(15,110);

/*triunghi_coliniar(p,q,r);
apartine_triunghi(p, q, r, k);*/

seg_intersect(p, q, r, k);

getch();
closegraph();
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.