<?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=427883&amp;view=findpost&amp;p=3868472</guid>
        <pubDate>Mon, 13 Jun 2022 08:53:57 +0000</pubDate>
        <title>Массив непересекающихся отрезков</title>
        <link>https://forum.sources.ru/index.php?showtopic=427883&amp;view=findpost&amp;p=3868472</link>
        <description><![CDATA[Psychologist: спасибо, разобрался еще вчера ночью:<br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">procedure TForm1.Button1Click(Sender: TObject);</div><div class="code_line">var i, k, N: Integer; buf_Rect: TRect; arec1: array of TRect;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;N := SpinEdit1.Value;</div><div class="code_line">&nbsp;&nbsp;k := 0;</div><div class="code_line">&nbsp;&nbsp;SetLength(arec1, k + 1);</div><div class="code_line">&nbsp;&nbsp;arec1[0].Left := Random(Image1.ClientWidth);</div><div class="code_line">&nbsp;&nbsp;arec1[0].Top := Random(Image1.ClientHeight);</div><div class="code_line">&nbsp;&nbsp;arec1[0].Right := Random(Image1.ClientWidth);</div><div class="code_line">&nbsp;&nbsp;arec1[0].Bottom := Random(Image1.ClientHeight);</div><div class="code_line">&nbsp;&nbsp;while k &#60; N do</div><div class="code_line">&nbsp;&nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;case RadioGroup1.ItemIndex of</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;0: begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;buf_Rect.Left := Random(Image1.ClientWidth);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;buf_Rect.Top := Random(Image1.ClientHeight);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;1: begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;buf_Rect.Left := arec1[High(arec1)].Right;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;buf_Rect.Top := arec1[High(arec1)].Bottom;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;buf_Rect.Right := Random(Image1.ClientWidth);</div><div class="code_line">&nbsp;&nbsp; &nbsp;buf_Rect.Bottom := Random(Image1.ClientHeight);</div><div class="code_line">&nbsp;&nbsp; &nbsp;for i := 0 to Length(arec1) - 1 do</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if CollisionLineFromTRECT(arec1[i], buf_Rect)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;then break else</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if i = Length(arec1) - 1 then</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Inc(k);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SetLength(arec1, k);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;arec1[k - 1] := buf_Rect;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">&nbsp;&nbsp;with Image1.canvas do</div><div class="code_line">&nbsp;&nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;fillrect(cliprect);</div><div class="code_line">&nbsp;&nbsp; &nbsp;for i := 0 to Length(arec1) - 1 do</div><div class="code_line">&nbsp;&nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;MoveTo(arec1[i].Left, arec1[i].Top);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;LineTo(arec1[i].Right, arec1[i].Bottom);</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">end;</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script><br>
<br>
<div class='tag-quote'><span class='tag-quote-prefix'>Цитата</span> <div class='quote '>с индексом k путаница</div></div><br>
да. во второй ветке оператора case. Исправил, теперь получаются непересекающиеся отрезки либо несамопересекающаяся ломаная, что мне и нужно было. спасибо за ответ]]></description>
        <author>Psychologist</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=427883&amp;view=findpost&amp;p=3868471</guid>
        <pubDate>Mon, 13 Jun 2022 08:41:48 +0000</pubDate>
        <title>Массив непересекающихся отрезков</title>
        <link>https://forum.sources.ru/index.php?showtopic=427883&amp;view=findpost&amp;p=3868471</link>
        <description><![CDATA[Писатель: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=427883&view=findpost&p=3868457'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Psychologist &#064; <time class="tag-quote__quoted-time" datetime="2022-06-12T21:53:10+00:00">12.06.22, 21:53</time></span><div class='quote '>Но не получается ни группа разрозненных отрезков, ни одна ломаная без самопересечений - что я делаю не так?</div></div><br>
Во-первых, вот здесь явно должно быть не<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">if CollisionLineFromTRECT(arec1[0], buf_Rect)</div></ol></div></div></div></div>а<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">if CollisionLineFromTRECT(arec1[i], buf_Rect)</div></ol></div></div></div></div><br>
А, во-вторых, у тебя с индексом k путаница.]]></description>
        <author>Писатель</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=427883&amp;view=findpost&amp;p=3868457</guid>
        <pubDate>Sun, 12 Jun 2022 21:53:10 +0000</pubDate>
        <title>Массив непересекающихся отрезков</title>
        <link>https://forum.sources.ru/index.php?showtopic=427883&amp;view=findpost&amp;p=3868457</link>
        <description><![CDATA[Psychologist: Доброго времени суток, эксперты.<br>
<br>
D7. Создаю массив значений типа TRect, для хранения отрезков. Хочу получить генерацию непересекающихся отрезков. Функцию для проверки пересечения отрезков, взял, с небольшой модификацией, <a class='tag-url' href='https://delphisources.ru/forum/showthread.php?t=20462' target='_blank'>отсюда</a>. Отрезки, которые касаются или даже накладываются друг на друга, она не считает пересекающимися, что мне подходит. N задаёт длину массива и число генераций. RadioGroup1 позволяет выбрать, отдельные отрезки будут генерироваться или одна ломаная линия. Но не получается ни группа разрозненных отрезков, ни одна ломаная без самопересечений - что я делаю не так?<br>
<br>
Спасибо<br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">function CollisionLineFromTRECT(Sect1, Sect2: TRect): boolean;</div><div class="code_line">var v1, v2, v3, v4: double; LA1, LB1, LA2, LB2: TPoint;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;LA1 := Point(Sect1.Left, Sect1.Top);</div><div class="code_line">&nbsp;&nbsp;LB1 := Point(Sect1.Right, Sect1.Bottom);</div><div class="code_line">&nbsp;&nbsp;LA2 := Point(Sect2.Left, Sect2.Top);</div><div class="code_line">&nbsp;&nbsp;LB2 := Point(Sect2.Right, Sect2.Bottom);</div><div class="code_line">&nbsp;&nbsp;v1 := (lb2.X - la2.X) * (la1.y - la2.y) - (lb2.y - la2.y) * (la1.X - la2.X);</div><div class="code_line">&nbsp;&nbsp;v2 := (lb2.X - la2.X) * (lb1.y - la2.y) - (lb2.y - la2.y) * (lb1.X - la2.X);</div><div class="code_line">&nbsp;&nbsp;v3 := (lb1.X - la1.X) * (la2.y - la1.y) - (lb1.y - la1.y) * (la2.X - la1.X);</div><div class="code_line">&nbsp;&nbsp;v4 := (lb1.X - la1.X) * (lb2.y - la1.y) - (lb1.y - la1.y) * (lb2.X - la1.X);</div><div class="code_line">&nbsp;&nbsp;CollisionLineFromTRECT := (v1 * v2 &#60; 0) and (v3 * v4 &#60; 0);</div><div class="code_line">&nbsp;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure TForm1.FormCreate(Sender: TObject);</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;Randomize;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure TForm1.Button1Click(Sender: TObject);</div><div class="code_line">var i, k, N: Integer; buf_Rect: TRect; arec1: TArrayOfRects;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;N := SpinEdit1.Value;</div><div class="code_line">&nbsp;&nbsp;k := 0;</div><div class="code_line">&nbsp;&nbsp;SetLength(arec1, k + 1);</div><div class="code_line">&nbsp;&nbsp;arec1[0].Left := Random(Image1.ClientWidth);</div><div class="code_line">&nbsp;&nbsp;arec1[0].Top := Random(Image1.ClientHeight);</div><div class="code_line">&nbsp;&nbsp;arec1[0].Right := Random(Image1.ClientWidth);</div><div class="code_line">&nbsp;&nbsp;arec1[0].Bottom := Random(Image1.ClientHeight);</div><div class="code_line">&nbsp;&nbsp;while k &#60; N do</div><div class="code_line">&nbsp;&nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;case RadioGroup1.ItemIndex of</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;0: begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;buf_Rect.Left := Random(Image1.ClientWidth);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;buf_Rect.Top := Random(Image1.ClientHeight);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;1: begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;buf_Rect.Left := arec1[k].Right;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;buf_Rect.Top := arec1[k].Bottom;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;buf_Rect.Right := Random(Image1.ClientWidth);</div><div class="code_line">&nbsp;&nbsp; &nbsp;buf_Rect.Bottom := Random(Image1.ClientHeight);</div><div class="code_line">&nbsp;&nbsp; &nbsp;for i := 0 to Length(arec1) - 1 do</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if CollisionLineFromTRECT(arec1[0], buf_Rect)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;then break else</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if i = Length(arec1) - 1 then</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Inc(k);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SetLength(arec1, k);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;arec1[k - 1] := buf_Rect;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">&nbsp;&nbsp;with Image1.canvas do</div><div class="code_line">&nbsp;&nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;fillrect(cliprect);</div><div class="code_line">&nbsp;&nbsp; &nbsp;for i := 0 to Length(arec1) - 1 do</div><div class="code_line">&nbsp;&nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;MoveTo(arec1[i].Left, arec1[i].Top);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;LineTo(arec1[i].Right, arec1[i].Bottom);</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">end;</div></ol></div></div></div></div><br>
<span class="b-attach" data-size="7575" data-hits="6" data-attach-id="63519" data-attach-post-id="0">
			<span class="b-attach__title"></span><a class='b-attach-link' href='https://forum.sources.ru/index.php?act=Attach&amp;type=post&amp;id=0&amp;attach_id=63519' title='Скачать файл' target='_blank'>ForNonCrossedSection.zip</a> (, : 6)
		</span>]]></description>
        <author>Psychologist</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      </channel>
      </rss>
	