Консультация № 181751
05.01.2011, 15:58
75.00 руб.
0 2 0
Здравствуйте, уважаемые эксперты! Прошу Вас ответить на следующий вопрос:
Задача: нужно определить, попадает ли точка в в указанные сектора:
R=33, a=33, b=20.
По X точка пересечения окружности -30, эллипса -18. По Y окружность -34, эллипс -27 соответственно


Код:
Program Shema;
Uses crt,Graph;
const r=33;
a=33;
b=20;
Var driver,mode:integer;
x0e,y0e,x0k,y0k:real;
dx,yk,ye,yp:real;
k:integer;
x,y:real;
x1,y1,x2,y2:real;
ak,pr:integer;
menu:boolean;
key:char;

procedure vivod;
begin RestoreCRTMode;
clrscr;
pr:=0;
writeln('основные данные: ');
writeln;
writeln('координаты центра окружности: ');
writeln('x0k= ',x0k:3:3,' y0k= ',y0k:3:3);
writeln('координаты центра эллипса : ');
writeln('x0e= ',x0e:3:3,' y0e= ',y0e:3:3);
writeln;
writeln('координаты точки пересечения эллипса и круга: x= ',x1:3:3,'; y= ',y1:3:3);
writeln('координаты пересечения круга и прямой: x= ',x2:3:3,'; y= ',y2:3:3);
writeln;
writeln('радиус окружности r= ',r);
writeln('параметр эллипса a= ',a);
writeln('параметр эллипса b= ',b);
writeln;
writeln('нажмите любую клавишу для продолжения.');
readkey;
setgraphmode(getgraphmode);
end;

procedure proverka;
begin restorecrtmode;
clrscr;
writeln('‚ввод координат проверяемой точки.');
writeln;
write('‚введите абциссу проверяемой точки: x= ');
readln(x);
write('‚введите ординату проверяемой точки: y= ');
readln(y);
pr:=0;
if (x<(x0k+r))and(x>(x0e-a))and(y<y1)and(y>(y0e-b))
then begin if x>0
then k:=-1
else k:=1;
yk:=k*sqrt(r*r-sqr(x-x0k))+y0k;
ye:=b*k*sqrt(1-(sqr(x-x0e)/(a*a)))+y0e;
yp:=(((x-x1)*(y2-y1))/(x2-x1))+y1;

if (x<0)and(y>0)and(y<yp)and(y<ye)
then pr:=1
else if (x>0)and(y<0)and(y>yk)and(y>ye)
then pr:=2
else pr:=3;

end
else pr:=3;

writeln;
writeln('нажмите любую клавишу для продолжения.');
readkey;
setgraphmode(getgraphmode);
end;

begin clrscr;
x0k:=-34+r;
y0k:=round((-39+sqrt(r*r-sqr(0-x0k)))*1000)/1000;
y0e:=40-b;
x0e:=round((37-a*sqrt(1-sqr(0-y0e)/sqr(b)))*1000)/1000;

dx:=x0e-a;
repeat
begin ye:=b*sqrt(1-sqr(dx-x0e)/sqr(a))+y0e;
yk:=sqrt(r*r-sqr(dx-x0k))+y0k;
dx:=dx+0.0001
end;
until ye<yk;
x1:=dx;
y1:=yk;

x2:=round((sqrt(r*r-sqr(0-y0k))-x0k)*1000)/1000;
y2:=0;

driver:=detect;
initgraph(driver,mode,'graph.tpu');
ak:=1;
menu:=false;
repeat
setcolor(8);
moveto(0,150); lineto(300,150);
moveto(150,0); lineto(150,300);

outtextxy(295,140,'X');
outtextxy(155,5,'Y');

circle((round(x0k)*2+150),((-2)*round(y0k)+150),r*2);
ellipse((round(x0e)*2+150),((-2)*round(y0e)+150),0,360,a*2,b*2);

moveto((round(x1)*2)+157,(round(y1)*(-2))+146);
lineto((round(x2)*2)+139,(round(y2)*(-2))+150);

setfillstyle(1,red);
floodfill(150-2,150-2,8);
setfillstyle(1,1);
floodfill(150+2,150+2,8);

outtextxy(320,50,'на схеме обозначены:');
outtextxy(320,70,'красным область А');
outtextxy(320,90,'Синим область В');
outtextxy(320,110,'белой точкой-проверяемая точка ');

if pr<>0
then putpixel(round(x)*2+150,150-round(y)*2,15);
if pr=1
then outtextxy(220,230,'Проверяемая точка лежит в области А');
if pr=2
then outtextxy(230,230,'Проверяемая точка лежит в области В');
if pr=3
then outtextxy(230,230,'Проверяемая точка не лежит ни в одной области');


if ak=1
then begin setcolor(red);
rectangle(50,350,270,370);
setfillstyle(1,1);
floodfill(52,352,4);
setcolor(7);
end
else begin setcolor(0);
rectangle(50,350,270,370);
setfillstyle(1,0);
floodfill(52,352,0);
setcolor(7);
end;
if ak=2
then begin setcolor(red);
rectangle(50,370,270,390);
setfillstyle(1,1);
floodfill(52,372,4);
setcolor(7);
end
else begin setcolor(0);
rectangle(50,370,270,390);
setfillstyle(1,0);
floodfill(52,372,0);
setcolor(7);
end;
if ak=3
then begin setcolor(red);
rectangle(50,390,270,410);
setfillstyle(1,1);
floodfill(52,392,4);
setcolor(7);
end
else begin setcolor(0);
rectangle(50,390,270,410);
setfillstyle(1,0);
floodfill(52,392,0);
setcolor(7);
end;
Outtextxy(55,355,'‚ввести координаты точки');
Outtextxy(55,375,'основные данные');
Outtextxy(55,395,'‚Выход из программы ');

Outtextxy(25,425,'Клавиша z- сдвиг вниз');
Outtextxy(25,435,'Клавиша а- сдвиг вверх');
Outtextxy(25,445,'Клавиша enter - выбор');

key:=readkey;
if (key='z')and(ak<3)
then ak:=ak+1;
if (ak>1)and(key='a')
then ak:=ak-1;

if (key=#13)and(ak=3)
then menu:=true;
if (key=#13)and(ak=2)
then vivod;
if (key=#13)and(ak=1)
then proverka;

cleardevice;

until menu;

end.

компиляция проходит, но программа не запускается (exited with exitcode=207):

Обсуждение

давно
Профессор
230118
3054
05.01.2011, 17:31
общий
Эта ошибка означает
One of the following floating-point errors occured:

- The real value passed to Trunc or Round could not be converted to an Integer within the
Longint range (-2147483648 to 2147483647).
- The argument passed to the Sqrt function was negative.
- The argument passed to the Ln function was zero or negative.
- An 80x87 stack overflow occurred.
У Вас, вероятно, Turbo Pascal
На Lazarus программа не компилировалась из-за строки initgraph(driver,mode,'graph.tpu'); Поменяла тип переменных на smallint, и успешно работает. Попробуйте так же.
давно
Мастер-Эксперт
325460
1469
06.01.2011, 11:19
общий
уже был подобный вопрос, ответом было то, что не правильно выбран тип данных и происходит переполнение, предыдущий ответ это только подтвердил.
Перепроверьте типы данных, сделайте их чтобы можно было вместить больше единиц.
Об авторе:
to live is to die
Форма ответа