<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=26321&amp;view=findpost&amp;p=185884</guid>
        <pubDate>Wed, 20 Mar 2002 14:15:25 +0000</pubDate>
        <title>B-сплайн</title>
        <link>https://forum.sources.ru/index.php?showtopic=26321&amp;view=findpost&amp;p=185884</link>
        <description><![CDATA[Kuss: #include &lt;graphics.h&gt;<br>#include &lt;conio.h&gt;<br>#include &lt;stdio.h&gt;<br>#define MAX 100<br>#define N 8<br>#define ZOOM 2<br><br>enum TypeSpline {Bezier,BSpline,Ermit};<br><br>inline double BezierFunc(double p[],int i,double t)<br>{<br> double s=1-t,<br> &nbsp; &nbsp; &nbsp;t2=t*t,<br> &nbsp; &nbsp; &nbsp;t3=t2*t;<br> return ((p[3*i]*s+3*t*p[3*i+1])*s+3*t2*p[3*i+2])*s+t3*p[3*i+3];<br>}<br><br>inline double BSplineFunc(double p[],int i,double t)<br>{<br> double s=1-t,<br> &nbsp; &nbsp; &nbsp;t2=t*t,<br> &nbsp; &nbsp; &nbsp;t3=t2*t;<br> return (s*s*s*p[i]+(3*t3-6*t2+4)*p[i+1]+(-3*t3+3*t2+3*t+1)*p[i+2]+t3*p[i+3])/6.0;<br>}<br><br>inline double ErmitFunc(double p[],int i,double t)<br>{<br> double t2=t*t,<br> &nbsp; &nbsp; &nbsp;t3=t2*t;<br> return (2*t3-3*t2+1)*p[i]+(-2*t3+3*t2)*p[i+1]+(t3-2*t2+t)*(p[i+1]-p[i])+(t3-t2)*(p[i+2]-p[i+1]);<br>}<br><br>double (*Spline[])(double[],int,double)={BezierFunc,BSplineFunc,ErmitFunc};<br><br>inline int LoadFromFile(double a[],double b[],int &amp;c)<br>{<br> &nbsp;FILE *f;<br> &nbsp;c=0;<br> &nbsp;if((f=fopen(&quot;points.ptn&quot;,&quot;r&quot;))==NULL) {<br> &nbsp; &nbsp; puts(&quot;\nError: Can't open data file\n&quot;); return -1;}<br> &nbsp;while(!feof(f))<br> &nbsp; &nbsp;{<br> &nbsp; &nbsp; fscanf(f,&quot;\%lf&quot;,&amp;a[c]);<br> &nbsp; &nbsp; fscanf(f,&quot;\%lf&quot;,&amp;b[c]);<br> &nbsp; &nbsp; a[c]*=ZOOM;<br> &nbsp; &nbsp; b[c++]*=ZOOM;<br> &nbsp; &nbsp;}<br> &nbsp;fclose(f);<br> &nbsp;return 1;<br>}<br><br>inline void DrawFigure(double a[],double b[],int c,int xmid,int ymid,int col)<br>{<br> &nbsp;setcolor(col);<br> &nbsp;setlinestyle(1,1,2);<br> &nbsp;moveto(a[0]+xmid,b[0]+ymid);<br> &nbsp;for(int i=1;i&lt;c;i++)<br> &nbsp; &nbsp;lineto(a[i]+xmid,b[i]+ymid);<br>}<br><br>inline void DrawSpline(TypeSpline ts,double a[],double b[],int &amp;c,int xmid,int ymid,int col)<br>{<br> &nbsp;int i,j,end;<br> &nbsp;double xs,ys,dt;<br> &nbsp;char *s[]={ &nbsp; &quot; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Bezier Spline&quot;,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;B-Spline &nbsp; &nbsp;&quot;,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Ermit Spline &quot;};<br><br> &nbsp;setcolor(col);<br> &nbsp;setlinestyle(0,1,1);<br> &nbsp;switch(ts) {<br> &nbsp; &nbsp;case Bezier: end=c/3;break;<br> &nbsp; &nbsp;case BSpline: end=c-3;break;<br> &nbsp; &nbsp;case Ermit: end=c-2;break;}<br><br> &nbsp;moveto(Spline[ts](a,0,0.0)+xmid,Spline[ts](b,0,0.0)+ymid);<br> &nbsp;for(i=0;i&lt;end;i++)<br> &nbsp; &nbsp;for(j=0;j&lt;=N;j++) {<br> &nbsp; &nbsp; &nbsp;dt=(double)j/(double)N;<br> &nbsp; &nbsp; &nbsp;xs=Spline[ts](a,i,dt);<br> &nbsp; &nbsp; &nbsp;ys=Spline[ts](b,i,dt);<br> &nbsp; &nbsp; &nbsp;lineto(xs+xmid,ys+ymid);<br> &nbsp; &nbsp;}<br> &nbsp;outtextxy(0,0,s[ts]);<br>}<br><br>main()<br>{<br> &nbsp;TypeSpline type;<br> &nbsp;int count,gdr=DETECT,gmod;<br> &nbsp;initgraph(&amp;gdr,&amp;gmod,&quot;&quot;);<br><br> &nbsp;double x[MAX],y[MAX];<br> &nbsp;if(!LoadFromFile(x,y,count)) return -1;<br><br> &nbsp;for(type=Bezier;type&lt;=Ermit;type++) {<br> &nbsp; &nbsp;DrawFigure(x,y,count,320,240,14);<br> &nbsp; &nbsp;DrawSpline(type,x,y,count,320,240,15);<br> &nbsp; &nbsp;getch();<br> &nbsp; &nbsp;cleardevice();}<br>}<br>]]></description>
        <author>Kuss</author>
        <category>Алгоритмы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=26321&amp;view=findpost&amp;p=185883</guid>
        <pubDate>Tue, 19 Mar 2002 16:26:32 +0000</pubDate>
        <title>B-сплайн</title>
        <link>https://forum.sources.ru/index.php?showtopic=26321&amp;view=findpost&amp;p=185883</link>
        <description><![CDATA[Jk: Если кто-нибуть занимался subjem? В чем суть метода?<br>Или оставьте ссылки на материалы. Если у кого-нибудь есть электронный вариант книги Завьялова &quot;Сплайн-функции и их применение&quot;, буду очень признателен.]]></description>
        <author>Jk</author>
        <category>Алгоритмы</category>
      </item>
	
      </channel>
      </rss>
	