Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Delphi программирование > Паскаль, Turbo Pascal, PascalABC.NET
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 04.12.2008, 14:17   #1
Anton1997
 
Регистрация: 15.11.2008
Сообщений: 7
Восклицание Помогите с задачкой плизз!!! на Delphi

Написать функцию для про-верки того факта, лежит ли заданная точка А внутри или вне много-угольника. Многоугольник на плоскости (не обязательно выпуклый) задан своими вершинами в порядке обхода по часовой стрелке.

Последний раз редактировалось Anton1997; 05.12.2008 в 10:42.
Anton1997 вне форума Ответить с цитированием
Старый 04.12.2008, 17:41   #2
Anton1997
 
Регистрация: 15.11.2008
Сообщений: 7
По умолчанию

необязательно на паскале
Anton1997 вне форума Ответить с цитированием
Старый 05.12.2008, 10:25   #3
Anton1997
 
Регистрация: 15.11.2008
Сообщений: 7
По умолчанию

нашол функцию в делфи: Находится ли точка внутри многоугольника

function PtInRgn(TestPolygon : array of TPoint; const P : TPoint): boolean;
var
ToTheLeftofPoint, ToTheRightofPoint : byte;
np : integer;
OpenPolygon : boolean;
XIntersection : real;
begin
ToTheLeftofPoint := 0;
ToTheRightofPoint := 0;
OpenPolygon := False;

{Prufen ob das Polygon geschlossen ist}
{tests if the polygon is closed}

if not ((TestPolygon[0].X = TestPolygon[High(TestPolygon)].X) and
(TestPolygon[0].Y = TestPolygon[High(TestPolygon)].Y)) then
OpenPolygon := True;

{Tests fur jedes Paar der Punkte, um zu sehen wenn die Seite zwischen
ihnen, die horizontale Linie schneidet, die TestPoint durchlauft}
{tests for each couple of points to see if the side between them
crosses the horizontal line going through TestPoint}

for np := 1 to High(TestPolygon) do
if ((TestPolygon[np - 1].Y <= P.Y) and
(TestPolygon[np].Y > P.Y)) or
((TestPolygon[np - 1].Y > P.Y) and
(TestPolygon[np].Y <= P.Y))
{Wenn es so ist} {if it does}
then
begin
{berechnet die x Koordinate des Schnitts}
{computes the x coordinate of the intersection}

XIntersection := TestPolygon[np - 1].X +
((TestPolygon[np].X - TestPolygon[np - 1].X) /
(TestPolygon[np].Y - TestPolygon[np - 1].Y)) * (P.Y - TestPolygon[np - 1].Y);

{Zahler entsprechend verringern}
{increments appropriate counter}
if XIntersection < P.X then Inc(ToTheLeftofPoint);
if XIntersection > P.X then Inc(ToTheRightofPoint);
end;

{Falls das Polygon offen ist, die letzte Seite testen}
{if the polygon is open, test for the last side}

if OpenPolygon then
begin
np := High(TestPolygon); {Thanks to William Boyd - 03/06/2001}
if ((TestPolygon[np].Y <= P.Y) and
(TestPolygon[0].Y > P.Y)) or
((TestPolygon[np].Y > P.Y) and
(TestPolygon[0].Y <= P.Y)) then
begin
XIntersection := TestPolygon[np].X +
((TestPolygon[0].X - TestPolygon[np].X) /
(TestPolygon[0].Y - TestPolygon[np].Y)) * (P.Y - TestPolygon[np].Y);

if XIntersection < P.X then Inc(ToTheLeftofPoint);
if XIntersection > P.X then Inc(ToTheRightofPoint);
end;
end;

if (ToTheLeftofPoint mod 2 = 1) and (ToTheRightofPoint mod 2 = 1) then Result := True
else
Result := False;
end; {PtInRgn}
куда ее вставить и что кинуть на форму???
Anton1997 вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
помогите плизз с задачей на с++ Jet-Tea Общие вопросы C/C++ 3 05.10.2008 11:43
Я не верю!!!=(((Помогите,УМОЛЯЮ!!! Elm0 Свободное общение 6 03.10.2007 19:29
Помогите!!!плизз Хван Паскаль, Turbo Pascal, PascalABC.NET 11 14.01.2007 08:38