+ Reply to Thread
Results 1 to 3 of 3

Thread: КГ 18.10.12

  1. #1
    All knowing Bloo_uni's Avatar
    Join Date
    Oct 2010
    Posts
    182

    КГ 18.10.12

    2D графика с MinMax ф-ия, изчертаване на координатна система (х и у), изчертаване на Bezie линии, различни изчертавания на точки (с case-ове)


    Code:
    #include<iostream.h>
    #include<graphics.h>
    #include<conio.h>
    #include<dos.h>
    #include<math.h>
    #include<stdio.h>
    
    void MinMax(int m, double a[], double &min, double &max)
    {
    	min = a[0];
    	max = a[0];
    	for(int i=1; i<m; i++)
    	{
    		if(a[i]<min) min=a[i];
    		if(a[i]>max) max=a[i];
    	}
    }
    
    double Axis(int d, int p, int del, double min, double max, int x0, int y0)
    {
    	char buf[30];
    	int dx=p/del;
    	double s=((max - min)/p);
    	setcolor(11);
    	if(d==0)
    	{
    		line(x0, y0, (x0+p), y0);
    		for(int i=1; i<del; i++)
    		{
    		line((x0+i*dx), y0, (x0+i*dx), (y0+3));
    		sprintf(buf, "%.2f", (min+i*dx*s));
    		outtextxy((x0+i*dx), y0+10, buf);
    		}
    	}
    	  else
    	  {
    	  line(x0, y0, x0, (y0-p));
    	  for(int i=del; i>0; i--)
    		{
    		line(x0, (y0-i*dx), (x0-3), (y0-i*dx));
    		settextjustify(2,1);
    		sprintf(buf, "%.2f", (min+i*dx*s));
    		outtextxy((x0-10),(y0-i*dx), buf);
    		}
    	  }
    	  return s;
    }
    
    void Points(int n, double xp[], double yp[], int x0, int y0, int minX, int minY, double sx, double sy, int sp)
    {
    	 setcolor(12);
    	 for(int i=0; i<n; i++)
    	 switch(sp)
    	 {
    	 case 0:
    	 putpixel((x0+(xp[i]-minX)/sx), (y0-(yp[i]-minY)/sy),3); break;
    	 case 1:
    	 circle((x0+(xp[i]-minX)/sx), (y0-(yp[i]-minY)/sy),2); break;
    	 case 2:
    		 {
    		 line((x0+(xp[i]-minX)/sx)+3, (y0-(yp[i]-minY)/sy)-3, (x0+(xp[i]-minX)/sx)-3, (y0-(yp[i]-minY)/sy)+3);
    		 line((x0+(xp[i]-minX)/sx)-3, (y0-(yp[i]-minY)/sy)-3, (x0+(xp[i]-minX)/sx)+3, (y0-(yp[i]-minY)/sy)+3);
    		 } break;
    	 case 3:
    		 {
    		 line((x0+(xp[i]-minX)/sx), (y0-(yp[i]-minY)/sy)+2, (x0+(xp[i]-minX)/sx), (y0-(yp[i]-minY)/sy)-2);
    		 line((x0+(xp[i]-minX)/sx)-2, (y0-(yp[i]-minY)/sy), (x0+(xp[i]-minX)/sx)+2, (y0-(yp[i]-minY)/sy));
    		 } break;
    		 }
    }
    void CurveBezie(double masX[], double masY[], double masRx[], double masRy[], double masQx[], double masQy[], int m)
    {
    	 int n;
    	 for(double t=0; t<1; t+=0.01)
    	 {
    	 for(int i=0; i<m; i++)
    		 {
    		 masRx[i]=masX[i];
    		 masRy[i]=masY[i];
    		 }
    	 n=m;
    	 while(n>0)
    		 {
    		 for(i=0; i<n-1;i++)
    			 {
    			 masQx[i]=masRx[i]+(masRx[i+1]-masRx[i])*t;
    			 masQy[i]=masRy[i]+(masRy[i+1]-masRy[i])*t;
    			 }
    		 n=n-1;
    		 for(i=0;i<n;i++)
    			 {
    			 masRx[i]=masQx[i];
    			 masRy[i]=masQy[i];
    			 }
    		 }
    	 putpixel(masRx[0], masRy[0], 10);
    	}
    }
    void main()
    {
    	 clrscr();
    	 int gdriver=0, gmode;
    	 const int n=6;
    	 int x0=50;
    	 int y0=400;
    	 double masY[]={2.4, 3.1, 0, 1.7, 0.2, 1.5};
    	 double masX[]={8.00, 8.50, 9.00, 9.50, 10.00, 10.50};
    	 double masPx[6];
    	 double masPy[6];
    	 double masRx[6];
    	 double masRy[6];
    	 double masQx[6];
    	 double masQy[6];
    	 double minX, maxX, minY, maxY;
    	 MinMax(n, masX, minX, maxX);
    	 MinMax(n, masY, minY, maxY);
    	 initgraph(&gdriver, &gmode, "c:\\borlandc\\bgi");
    	 double sx, sy;
    	 sx = Axis(0, 400, 8, minX, maxX, x0, y0);
    	 sy = Axis(1, 300, 8, minY, maxY, x0, y0);
    	 for(int i = 0 ; i < 6; i ++)
    	 {
    		 masPx[i] = 50 + (masX[i]-minX)/sx;
    		 masPy[i] = 400 - (masY[i]-minY)/sy;
    	 }
    	 Points(6, masX, masY, x0, y0, minX, minY, sx, sy,  2);
    	 setcolor(4);
     //	 CurveBezie(masPx, masPy, masRx, masRy, masQx, masQy, 6);
    
    	 getche();
    	 closegraph();
    }
    Last edited by Bloo_uni; 25-10-2012 at 11:19 AM.

  2. #2
    Registered User
    Join Date
    Oct 2011
    Posts
    3
    Това ли е задачата за business графика, за която те питах? Doesn't seem like it.

  3. #3
    Nope. Това е 2D графика. То го пише :Д
    Чертае Х и У оси, оразмерява ги, слага им числа, чертае точки, а ако махнеш коментара на // CurveBezie.... накрая ти чертае и кривата на Безие (която така и не я взехме... но файла се казваше КГ10Упр.цпп ... та...да...)

    ПП: не, нямам бизнес графиката с bar chart-a. Yet*
    Crazy forum admin
    PS: sorry for adverts, but bills ain't gonna pay themselves

+ Reply to Thread

Similar Threads

  1. КГ- конспект 2013
    By Bloo in forum Комп. графика
    Replies: 0
    Last Post: 24-01-2013, 02:20 PM
  2. КГ 11.10.12
    By Bloo_uni in forum Комп. графика
    Replies: 0
    Last Post: 11-10-2012, 11:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts