Смекни!
smekni.com

Сглаженная поверхность для границы трех атомов в пространстве (стр. 2 из 2)

setcolor(svet);setlinestyle(0,0,1);

}

setcolor(svet);

setcolor(10);

char er[15];

sprintf(er,"ñôåðà ¹%d",i);

circle(x[i]+40,800-y[i],r[i]);outtextxy(x[i]+40,800-y[i],er);

ellipse(x[i]+40,800-y[i],180,360,r[i],r[i]/2);

ellipse(x[i]+40,800-y[i]-r[i]/2,180,360,r[i]-(x[i]+r[i]-(sqrt(r[i]*r[i]-(r[i]/2)*(r[i]/2))+x[i]))-2,r[i]/4);

ellipse(x[i]+40,800-y[i]+r[i]/2,180,360,r[i]-(x[i]+r[i]-(sqrt(r[i]*r[i]-(r[i]/2)*(r[i]/2))+x[i]))-2,r[i]/4);

setlinestyle(3,0,1);

ellipse(x[i]+40,800-y[i],0,180,r[i],r[i]/2);

ellipse(x[i]+40,800-y[i]-r[i]/2,0,180,r[i]-(x[i]+r[i]-(sqrt(r[i]*r[i]-(r[i]/2)*(r[i]/2))+x[i]))-2,r[i]/4);

ellipse(x[i]+40,800-y[i]+r[i]/2,0,180,r[i]-(x[i]+r[i]-(sqrt(r[i]*r[i]-(r[i]/2)*(r[i]/2))+x[i]))-2,r[i]/4);

if (raz==0) setlinestyle(0,0,1);

if (svet==2) svet=14;

else svet=svet-2;

}

}

raz=raz+1;

for(i=1;i<=3;i++)

{p[i]=z[i];}

p[4]=Zc;

if (raz==1) risuem();

}

void sechen(void)

{ setcolor(7);

setlinestyle(0,0,2);

double xp,yp,pol1,pol2,mon=0;

double x1,x2,y1,y2;

int i,smen=0,nt;

int Xmen;

double stat1,stat2,stat3,stat4,pl;

double AD,CB,ADY,DISC,ABD,AC,ABX;

double at,bt,ct,Yris1,Zris1,Yris2,Zris2,gr1,gr2,Xris1,Xris2;

for(i=0;i<3;i++)

{

if (i==0)

{

if (abs(Xkos3-Xkos1)>abs(Ykos3-Ykos1))

{

if (Ykos1>Ykos3) {pol2=Ykos1;pol1=Ykos3;}

else {pol2=Ykos3;pol1=Ykos1;}

smen=1;

if (Xkos1>Xkos3) {gr1=Xkos3;gr2=Xkos1;}

else {gr1=Xkos1;gr2=Xkos3;}

}

else

{ if (Xkos1>Xkos3) {pol2=Xkos1;pol1=Xkos3;}

else {pol2=Xkos3;pol1=Xkos1;}

smen=2;

if (Ykos1>Ykos3) {gr1=Ykos3;gr2=Ykos1;}

else {gr1=Ykos1;gr2=Ykos3;}

}

stat1=(Ykos3-Ykos1)*(Zc-Zkos1)-(Yc-Ykos1)*(Zkos3-Zkos1);

stat2=(Zkos3-Zkos1)*(Xc-Xkos1)-(Xkos3-Xkos1)*(Zc-Zkos1);

stat3=(Xkos3-Xkos1)*(Yc-Ykos1)-(Xc-Xkos1)*(Ykos3-Ykos1);

stat4=-(Xkos1*stat1+Ykos1*stat2+Zkos1*stat3);

}

if (i==1)

{

if (abs(Xkos2-Xkos1)>abs(Ykos2-Ykos1))

{

if (Ykos1>Ykos2) {pol2=Ykos1;pol1=Ykos2;}

else {pol2=Ykos2;pol1=Ykos1;}

smen=1;

if (Xkos1>Xkos2) {gr1=Xkos2;gr2=Xkos1;}

else {gr1=Xkos1;gr2=Xkos2;}

}

else

{ if (Xkos1>Xkos2) {pol2=Xkos1;pol1=Xkos2;}

else {pol2=Xkos2;pol1=Xkos1;}

smen=2;

if (Ykos1>Ykos2) {gr1=Ykos2;gr2=Ykos1;}

else {gr1=Ykos1;gr2=Ykos2;}

}

stat1=(Ykos2-Ykos1)*(Zc-Zkos1)-(Yc-Ykos1)*(Zkos2-Zkos1);

stat2=(Zkos2-Zkos1)*(Xc-Xkos1)-(Xkos2-Xkos1)*(Zc-Zkos1);

stat3=(Xkos2-Xkos1)*(Yc-Ykos1)-(Xc-Xkos1)*(Ykos2-Ykos1);

stat4=-(Xkos1*stat1+Ykos1*stat2+Zkos1*stat3);

}

if (i==2)

{

if (abs(Xkos3-Xkos2)>abs(Ykos3-Ykos2))

{

if (Ykos2>Ykos3) {pol2=Ykos2;pol1=Ykos3;}

else {pol2=Ykos3;pol1=Ykos2;}

smen=1;

if (Xkos2>Xkos3) {gr1=Xkos3;gr2=Xkos2;}

else {gr1=Xkos2;gr2=Xkos3;}

}

else

{ if (Xkos2>Xkos3) {pol2=Xkos2;pol1=Xkos3;}

else {pol2=Xkos3;pol1=Xkos2;}

smen=2;

if (Ykos2>Ykos3) {gr1=Ykos3;gr2=Ykos2;}

else {gr1=Ykos2;gr2=Ykos3;}

}

stat1=(Ykos3-Ykos2)*(Zc-Zkos2)-(Yc-Ykos2)*(Zkos3-Zkos2);

stat2=(Zkos3-Zkos2)*(Xc-Xkos2)-(Xkos3-Xkos2)*(Zc-Zkos2);

stat3=(Xkos3-Xkos2)*(Yc-Ykos2)-(Xc-Xkos2)*(Ykos3-Ykos2);

stat4=-(Xkos2*stat1+Ykos2*stat2+Zkos2*stat3);

}

mon=0;nt=0;

while (gr1<=gr2)

{ if (smen==1)

{CB=stat3/stat2;

AD=(-stat1*gr1)/stat2-(stat4/stat2);

ADY=(AD-Yc);

at=(CB*CB+1);

bt=(-2)*(ADY*CB+Zc);

ct=(ADY*ADY+Zc*Zc+(gr1-Xc)*(gr1-Xc)-Rc*Rc);

DISC=(bt/2)*(bt/2)-at*ct;

{

if (DISC>=0)

{ setcolor(9);

Zris2=((-bt/2)+sqrt(DISC))/at;

Zris1=((-bt/2)-sqrt(DISC))/at;

Yris1=AD-CB*Zris1;

Yris2=AD-CB*Zris2;

YY[schit]=Yris2;

ZZ[schit]=Zris2;

XX[schit]=gr1;

Rad[schit]=(sqrt((XX[schit]-Xvr)*(XX[schit]-Xvr)+(ZZ[schit]-Zvr)*(ZZ[schit]-Zvr)));

x1=XX[schit]-Xvr;x2=Rad[schit];y1=ZZ[schit]-Zvr;y2=0;

ugol[schit]=acos((x1*x2+y1*y2)/((sqrt(x1*x1+y1*y1)))/(sqrt(x2*x2+y2*y2)))*180/M_PI;

schit++;

// if (Yris2>pol1 && Yris2<pol2)

{if (mon==0) {xp=gr1;yp=Yris2;mon++;}

else {line(xp+40,800-yp,gr1+40,800-Yris2);mon=0;}

circle(gr1+40,800-Yris2,2);

} gr1=gr1+1;

}

}

}

if (smen==2)

{

ABD=(-stat2*gr1)/stat1-stat4/stat1;

AC=stat3/stat1;

ABX=ABD-Xc;

at=(AC*AC+1);

bt=(-2)*(ABX*AC+Zc);

ct=(ABX*ABX+Zc*Zc+(gr1-Yc)*(gr1-Yc)-Rc*Rc);

DISC=(bt/2)*(bt/2)-at*ct;

if (DISC>=0)

{

setcolor(9);

Zris2=((-bt/2)+sqrt(DISC))/at;

Zris1=((-bt/2)-sqrt(DISC))/at;

Xris1=ABD-AC*Zris1;

Xris2=ABD-AC*Zris2;

YY[schit]=gr1;

ZZ[schit]=Zris2;

XX[schit]=Xris2;

Rad[schit]=(sqrt((XX[schit]-Xvr)*(XX[schit]-Xvr)+(ZZ[schit]-Zvr)*(ZZ[schit]-Zvr)));

x1=XX[schit]-Xvr;x2=Rad[schit];y1=ZZ[schit]-Zvr;y2=0;

ugol[schit]=acos((x1*x2+y1*y2)/((sqrt(x1*x1+y1*y1)))/(sqrt(x2*x2+y2*y2)))*180/M_PI;

schit++;

{if (mon==0) {xp=Xris2;yp=gr1;mon++;}

else {line(xp+40,800-yp,40+Xris2,800-gr1);mon=0;}

circle(Xris2+40,800-gr1,2);

} gr1=gr1+1;

} }

}

}

double rk=0.0,pc;

if (Xkos1>rk) {rk=Xkos1;pc=Ykos1;}

if (Xkos1>rk) {rk=Xkos2;pc=Ykos2;}

if (Xkos1>rk) {rk=Xkos3;pc=Ykos3;}

setcolor(15);

setlinestyle(1,0,1);

line(Xc+40,800-Yc,x[1]+40,800-y[1]);

line(Xc+40,800-Yc,x[2]+40,800-y[2]);

line(Xc+40,800-Yc,x[3]+40,800-y[3]);

setlinestyle(0,0,1);

}

void raschet(void)

{ int i,kol=0;

aj=x[2]-x[1];

bj=y[2]-y[1];

cj=z[2]-z[1];

ak=x[3]-x[1];

bk=y[3]-y[1];

ck=z[3]-z[1];

Ris=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(x[1]-Xc)-(y[1]-Yc)*(y[1]-Yc))+z[1];

nom=0;

xc1=(Xc-double(x[1]))*(Xc-double(x[1]));

yc1=(Yc-double(y[1]))*(Yc-double(y[1]));

zc1=(Zc-double(z[1]))*(Zc-double(z[1]));

xc2=(Xc-double(x[2]))*(Xc-double(x[2]));

yc2=(Yc-double(y[2]))*(Yc-double(y[2]));

zc2=(Zc-double(z[2]))*(Zc-double(z[2]));

xc3=(Xc-double(x[3]))*(Xc-double(x[3]));

yc3=(Yc-double(y[3]))*(Yc-double(y[3]));

zc3=(Zc-double(z[3]))*(Zc-double(z[3]));

dg1=sqrt(xc1+yc1+zc1)-double(r[1])-Rc;

dg2=sqrt(xc2+yc2+zc2)-double(r[2])-Rc;

dg3=sqrt(xc3+yc3+zc3)-double(r[3])-Rc;

if (abs(int(dg1))<=1) nom++;

if (abs(int(dg2))<=1) nom++;

if (abs(int(dg3))<=1) nom++;

if (nom==3) {break;}

Zc=z[1]-sqrt((r[1]+Rc)*(r[1]+Rc)-(x[1]-Xc)*(x[1]-Xc)-(y[1]-Yc)*(y[1]-Yc));

nom=0;

xc1=(Xc-double(x[1]))*(Xc-double(x[1]));

yc1=(Yc-double(y[1]))*(Yc-double(y[1]));

zc1=(Zc-double(z[1]))*(Zc-double(z[1]));

xc2=(Xc-double(x[2]))*(Xc-double(x[2]));

yc2=(Yc-double(y[2]))*(Yc-double(y[2]));

zc2=(Zc-double(z[2]))*(Zc-double(z[2]));

xc3=(Xc-double(x[3]))*(Xc-double(x[3]));

yc3=(Yc-double(y[3]))*(Yc-double(y[3]));

zc3=(Zc-double(z[3]))*(Zc-double(z[3]));

dg1=sqrt(xc1+yc1+zc1)-double(r[1])-Rc;

dg2=sqrt(xc2+yc2+zc2)-double(r[2])-Rc;

dg3=sqrt(xc3+yc3+zc3)-double(r[3])-Rc;

if (abs(int(dg1))<=1) nom++;

if (abs(int(dg2))<=1) nom++;

if (abs(int(dg3))<=1) nom++;

if (nom==3) {break;}

j++;

}

R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*Xc/yc3-xc3*x[3]/yc3+(Yc-y[3])+zc3*Zc/yc3-zc3*z[3]/yc3);

Xkos1=Ykos1*xc1/yc1+XYc1;Xkos2=Ykos2*xc2/yc2+XYc2;Xkos3=Ykos3*xc3/yc3+XYc3;

Zkos1=Ykos1*zc1/yc1+ZYc1;Zkos2=Ykos2*zc2/yc2+ZYc2;Zkos3=Ykos3*zc3/yc3+ZYc3;

}

void osi(void)

{

int i,s=40;

char st[14];

setcolor(15);

line(40,40,40,800);

line(40,800,1000,800);

for(i=60;i<1000;i=i+20)

{line(i,798,i,802);}

for(i=80;i<1000;i=i+40)

{ sprintf(st,"%d",s);

outtextxy(i-7,810,st);

s=s+40;}

line(1000,800,985,795);

line(1000,800,985,805);

for(i=60;i<800;i=i+20)

{line(38,i,42,i);}

line(40,40,35,55);

line(40,40,45,55);

s=40;

for(i=760;i>40;i=i-40)

{ sprintf(st,"%d",s);

outtextxy(10,i-7,st);

s=s+40;

}

outtextxy(25,790,"0");

}

void menu()

{

int c=-1,i;

while(c!=ESC)

{

c=getch();

if (c==DOWN)

{ int re=0;

floodfill(10,10,3);

al1=al1+5;al2=al2+5;al3=al3+5;al4=al4+5;

z[1]=Zvr+R1*sin(al1*M_PI/180);

x[1]=Xvr+R1*cos(al1*M_PI/180);

z[2]=Zvr+R2*sin(al2*M_PI/180);

x[2]=Xvr+R2*cos(al2*M_PI/180);

z[3]=Zvr+R3*sin(al3*M_PI/180);

x[3]=Xvr+R3*cos(al3*M_PI/180);

Zc=Zvr+R4*sin(al4*M_PI/180);

Xc=Xvr+R4*cos(al4*M_PI/180);

raz=0;osi();risuem();

setcolor(9);

for(i=0;i<schit;i++)

{

ugol[i]=ugol[i]+5;

XX[i]=Xvr+Rad[i]*cos(ugol[i]*M_PI/180);

circle(XX[i]+40,800-YY[i],2);

}

setcolor(15);

setlinestyle(1,0,1);

line(Xc+40,800-Yc,x[1]+40,800-y[1]);

line(Xc+40,800-Yc,x[2]+40,800-y[2]);

line(Xc+40,800-Yc,x[3]+40,800-y[3]);

setlinestyle(0,0,1);

}

if (c==UP)

{ floodfill(10,10,3);

al1=al1-5;al2=al2-5;al3=al3-5;al4=al4-5;

z[1]=Zvr+R1*sin(al1*M_PI/180);

x[1]=Xvr+R1*cos(al1*M_PI/180);

z[2]=Zvr+R2*sin(al2*M_PI/180);

x[2]=Xvr+R2*cos(al2*M_PI/180);

z[3]=Zvr+R3*sin(al3*M_PI/180);

x[3]=Xvr+R3*cos(al3*M_PI/180);

Zc=Zvr+R4*sin(al4*M_PI/180);

Xc=Xvr+R4*cos(al4*M_PI/180);

raz=0;osi();risuem();

setcolor(9);

for(i=0;i<schit;i++)

{

ugol[i]=ugol[i]-5;

XX[i]=Xvr+Rad[i]*cos(ugol[i]*M_PI/180);

circle(XX[i]+40,800-YY[i],2);

}

setcolor(15);

setlinestyle(1,0,1);

line(Xc+40,800-Yc,x[1]+40,800-y[1]);

line(Xc+40,800-Yc,x[2]+40,800-y[2]);

line(Xc+40,800-Yc,x[3]+40,800-y[3]);

setlinestyle(0,0,1);

} }}

int main()

{

dano();

raschet();

osi();

risuem();

sechen();

menu();

getch();

return 0;

}