Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Лабы / BEZIE / BEZIE_2D

.CPP
Скачиваний:
23
Добавлен:
16.04.2013
Размер:
1.28 Кб
Скачать
//Ї®бв஥­ЁҐ ЄаЁў®© ЃҐ§мҐ

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


int Px[4],Py[4];

double Bezie(int i, double t)
{
   double b;
   switch(i)
   {
     case 0  : b=(1-t)*(1-t)*(1-t); break;
     case 1  : b=3*t*(1-t)*(1-t);   break;
     case 2  : b=3*t*t*(1-t);       break;
     case 3  : b=t*t*t;             break;
     default : printf("\nError in function Bezie"); exit(1);
   }
   return b;
}

double splineX(double t)
{
  double S=0;
  for(int i=0; i<4; i++)
    S += Px[i]*Bezie(i,t);
  return S;
}

double splineY(double t)
{
  double S=0;
  for(int i=0; i<4; i++)
    S += Py[i]*Bezie(i,t);
  return S;
}


void main()
{
  Px[0]=300; Px[1]=100; Px[2]=400; Px[3]=500;
  Py[0]=50; Py[1]=400; Py[2]=100; Py[3]=400;




  int driver=DETECT;
  int mode;
  int res;

  initgraph(&driver,&mode,"c:\\mathemat\\borlandc\\bgi");
  if((res=graphresult())!=grOk)
  {
    printf("\nGraphics error: %s",grapherrormsg(res));
    exit(1);
  }

  int i;
  for(i=0; i<3; i++)
    line(Px[i],Py[i],Px[i+1],Py[i+1]);
  int N=100;
  double t,dt=1.0/N;
  for(i=0; i<N; i++)
  {
    t=dt*i; putpixel((int)splineX(t),(int)splineY(t),14);
  }


   getch();
   closegraph();

}
Соседние файлы в папке BEZIE