0% found this document useful (0 votes)
28 views2 pages

C and C++ Graphics: Koch Curve & Hermite Curve

The document contains C code to draw a Hermite curve between two points. It defines a point structure with x and y coordinates and a hermite function that takes the two points and their tangents as parameters. It uses a t parameter from 0 to 1 to calculate the x and y coordinates along the curve via a Hermite interpolation formula. Pixels are drawn along the curve to display it on screen. The main function gets input for the points and tangents, calls hermite to draw the curve, and waits for user input before closing the graphics window.
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)
28 views2 pages

C and C++ Graphics: Koch Curve & Hermite Curve

The document contains C code to draw a Hermite curve between two points. It defines a point structure with x and y coordinates and a hermite function that takes the two points and their tangents as parameters. It uses a t parameter from 0 to 1 to calculate the x and y coordinates along the curve via a Hermite interpolation formula. Pixels are drawn along the curve to display it on screen. The main function gets input for the points and tangents, calls hermite to draw the curve, and waits for user input before closing the graphics window.
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

#include<stdio.

h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void c_cur(float x, float y, int len, float alpha, int n)
{
if(n>0) {
len=len/sqrt(2.0);
c_cur(x,y,len,alpha+45, n-1);
x=x+len*cos(alpha+45);
y=y+len*sin(alpha+45);
c_cur(x,y,len,alpha-45, n-1);
}
else
line(x,y, x+len*cos(alpha),y+len*sin(alpha));
}
void main() {
float x,y;
int len,n;
float alpha;
int gd =DETECT, gm;
printf("enter x,y,len,a,n 200 200 100 70 12");
scanf("%f%f%d%f%d",&x,&y,&len,&alpha,&n);
initgraph(&gd,&gm,"");
c_cur(x,y,len,alpha-65, n-1);
getch(); }

#include<iostream.h>
#include<graphics.h>
#include<conio.h>
#include<stdio.h>

struct point
{
int x,y;
};

void hermite(point p1,point p4,double r1,double r4)


{
float x,y,t;
for(t=0.0;t<=1.0;t+=.001)
{
x=(2*t*t*t-3*t*t+1)*p1.x+(-2*t*t*t+3*t*t)*p4.x+(t*t*t-
2*t*t+t)*r1+(t*t*t-t*t)*r4;
y=(2*t*t*t-3*t*t+1)*p1.y+(-2*t*t*t+3*t*t)*p4.y+(t*t*t-
2*t*t+1)*r1+(t*t*t-t*t)*r4;
putpixel(x,y,YELLOW);
}
}

int main()
{
int gd=DETECT,gm;
double r1,r4;
initgraph(&gd,&gm,"..//BGI");
point p1,p2;
printf("Enter 2 hermite points:\n");
scanf("%d%d%d%d",&p1.x,&p1.y,&p2.x,&p2.y);
printf("Enter the tangents at p1,p4");
scanf("%d%d",&r1,&r4);
cleardevice();
hermite(p1,p2,r1,r4);
putpixel(x1,y1,WHITE);
putpixel(x2,y2,WHITE);
getch();
closegraph();
return 0;
}

You might also like