1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #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; } |
Description :
This is the one stop educational site for all Electronic and Computer students. If you want to learn something new then we are here to help. We work on Microcontroller projects, Basic Electronics, Digital electronics, Computer projects and also in basic c/c++ programs.
#Home #Sitemap #Resources #Terms of Use
Copyright©2012 electrofriends.com All Rights Reserved
Contact:info@electrofriends.com
its not working.
#include
#include
int line1(int,int,int,int);
void hermite(int x1,int y1,int x2,int y2,float slope1,float slope2)
{
float x,y;
float u;
for(u=0.00;u<=1.0;u+=0.001)
{
x=(2*u*u*u-3*u*u+1)*x1+(-2*u*u*u+3*u*u)*x2+(u*u*u-2*u*u+u)*slope1*x1+(u*u*u-u*u)*slope2*x2;
y=(2*u*u*u-3*u*u+1)*y1+(-2*u*u*u+3*u*u)*y2+(u*u*u-2*u*u+u)*slope1*x1+(u*u*u-u*u)*slope2*x2;
putpixel(20+(int)(x+0.5),240-(int)(y+0.5),RED);
}
}
int main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
int i,j,k,l,m,n,x,y,z;
//hermite(10,10,100,100,3,4);
hermite(100,50,100,100,0.9,-1);
line1(100,0,100,100);
line1(100,50,120,0);
line1(140,0,150,100);
line1(150,100,160,0);
line1(145,50,155,50);
line1(180,0,180,100);
line1(180,100,200,0);
line1(200,0,200,100);
line1(220,0,230,100);
line1(230,100,240,0);
line1(225,50,235,50);
getch();
closegraph();
return 0;
}
int line1(int x1,int y1,int x2,int y2)
{
setcolor(RED);
line(20+x1,240-y1,20+x2,240-y2);
return 0;
}