0% found this document useful (0 votes)
31 views3 pages

Circle Mi

The document contains C code for drawing lines and rectangles using parametric equations. It includes functions for calculating parametric values, drawing lines and rectangles, and recursively dividing lines to draw them within a rectangular region.

Uploaded by

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

Circle Mi

The document contains C code for drawing lines and rectangles using parametric equations. It includes functions for calculating parametric values, drawing lines and rectangles, and recursively dividing lines to draw them within a rectangular region.

Uploaded by

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

#include<stdio.

h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void parametric(int
int rx = x1
int ry = y1
printf("%d,
}

x1, int y1, int x2, int y2, float t){


+ (x2-x1)*t;
+ (y2-y1)*t;
%d\n", rx, ry);

float getT(int i, int j, int x1, int y1, int rx, int ry, int x2, int y2){
float numer = (x1-rx)*i + (y1-ry)*j;
float denom = (x2-x1)*(-i) + (y2-y1)*(-j);
return numer/denom;
}
float max(float a, float b, float c){
printf("max passed %f, %f, %f\n", a, b, c);
if(a>b && a>c)return a;
else if(b>a && b>c)return b;
else return c;
}
float min(float a, float b, float c){
printf("min passed %f, %f, %f\n", a, b, c);
if(a<b && a<c)return a;
else if(b<a && b<c)return b;
else return c;
}
void putT(float t, int x1, int y1, int x2, int y2, int *px1, int *py1){
int x = int(x1 + (x2-x1)*t);
int y = int(y1 + (y2-y1)*t);
*px1 = x;
*py1 = y;
}
void drawRectangle(int
rx1 = rx1*10;
rx2 = rx2*10;
ry1 = ry1*10;
ry2 = ry2*10;
rx1 = 320+rx1;
rx2 = 320+rx2;
ry1 = 240-ry1;
ry2 = 240-ry2;
line(rx1, ry1,
line(rx1, ry2,
line(rx2, ry2,
line(rx1, ry1,
}

rx1, int ry1, int rx2, int ry2){

rx1,
rx2,
rx2,
rx1,

ry2);
ry2);
ry1);
ry2);

void foo(){
int x,y,r,h,de,dse;
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"C:\\TC\\BGI");
line(0,240,640,240);
line(320,0,320,480);

int x1=-4, y1=-2, x2=9, y2=3;


int rx1=0, rx2=8, ry1=0, ry2=4;
//
//

parametric(x1, y1, x2, y2, 0.0);


parametric(x1, y1, x2, y2, 1.0);
if((x2-x1)*(-1) + y2-y1
//pot enter
float tleft =
float tright = getT(1,
float ttop
= getT(0,
float tbottom = getT(0,

//printf("the
// printf("the
//
printf("the
//
printf("the

value
value
value
value

of
of
of
of

< 0){
getT(-1, 0, x1, y1, rx1, ry2, x2, y2);
0, x1, y1, rx2, ry2, x2, y2);
1, x1, y1, rx1, ry2, x2, y2);
-1, x1, y1, rx1, ry1, x2, y2);

tleft
tbottom
tright
ttop

=
=
=
=

%f
%f
%f
%f

%f\n",
%f\n",
%f\n",
%f\n",

tleft ,
tbottom,
tright ,
ttop ,

4.0/13);
2.0/5);
12.0/13);
6.0/5.0);

printf("\n\n");
printf("The minimum value is %f\n", min(1.0, float(tright) , float(ttop)
));
printf("The maximum value is %f\n", max(0.0, float(tbottom), float(tleft
)));
float t1 = min(1.0, float(tright) , float(ttop ));
float t2 = max(0.0, float(tbottom), float(tleft));
int px1;
int py1;
int px2;
int py2;
putT(t1, x1, y1, x2, y2, &px1, &py1);
putT(t2, x1, y1, x2, y2, &px2, &py2);
//
//

printf("\n\nSelected point1 :(%d, %d)\n", px1, py1);


printf("\n\nSelected point2 :(%d, %d)\n", px2, py2);
drawRectangle(rx1, ry1, rx2, ry2);
line(320+px1*10, 240-py1*10, 320+px2*10, 240-py2*10);
}else{
// pot decre
}
getch();
closegraph();

}
void linedd(int x1, int y1, int x2, int y2){
x1 *= 10;
y1 *= 10;
x2 *= 10;
y2 *= 10;
line(320+x1, 240-y1, 320+x2, 240-y2);
}
void drawLine(int x1, int y1, int x2, int y2,
int rx1, int ry1, int rx2, int ry2){
//
delay(2000);

drawRectangle(rx1, ry1, rx2, ry2);


printf("passed %d,%d AND %d,%d\n", x1, y1, x2, y2);
printf("rectan %d,%d AND %d,%d\n\n", rx1, ry1, rx2, ry2);
if(x1>=x2 || y1>=y2){
return;
}else if(x1>=rx1 && x1<=rx2 && y1>=ry1 && y1<=ry2 &&
x2>=rx1 && x2<=rx2 && y2>=ry1 && y2<=ry2){
linedd(x1, y1, x2, y2);
}else if(x2<=rx1 || x1>=rx2 || y2<=ry1 || y1>=ry2){
return;
}else{
int mx = (x1+x2)/2;
int my = (y1+y2)/2;
drawLine(x1, y1, mx, my, rx1, ry1, rx2, ry2);
drawLine(mx, my, x2, y2, rx1, ry1, rx2, ry2);
}
//
((x1>=rx1 && x1<=rx2 && y1>=ry1 && y1<=ry2) ||
//
(x2>=rx1 && x2<=rx2 && y2>=ry1 && y2<=ry2))
}
void main(){
int x,y,r,h,de,dse;
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"C:\\TC\\BGI");
line(0,240,640,240);
line(320,0,320,480);
int x1=-4, y1=-2, x2=9, y2=3;
int rx1=0, rx2=8, ry1=0, ry2=4;
drawLine(x1, y1, x2, y2, rx1, ry1, rx2, ry2);
getch();
closegraph();
}

You might also like