<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Punkte in Vieleck validieren]]></title><description><![CDATA[<p>Hi Community,</p>
<p>Ich komme bei einem Problem nicht weiter... Und zwar habe ich ca. 60 tausend Punkte als Geokoordinaten und bekomme von einer anderen Quelle 3-x Koordinaten und ich soll alle Punkte ausgeben die in diesen Vieleck liegen.<br />
Das ganze sollte schon relativ performant funktionieren und ich habe noch keine wirkliche Idee um dies zu lösen. Meine mathematischen Fähigkeiten beschränken sich leider auch nur auf ein Leistungskurs den ich mit 12 Punkten abgeschlossen habe.</p>
<p>Ich weiß das es nicht direkt ein Problem in C++ ist aber ich habe keine Kategorie gefunden in die es besser passen könnte da ich dies mit C++ verwirklichen muss.</p>
<p>Mit freundlichen Grüßen<br />
Synonym</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/325937/punkte-in-vieleck-validieren</link><generator>RSS for Node</generator><lastBuildDate>Wed, 11 Nov 2026 22:42:20 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/325937.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 24 May 2014 12:36:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Punkte in Vieleck validieren on Sat, 24 May 2014 12:36:24 GMT]]></title><description><![CDATA[<p>Hi Community,</p>
<p>Ich komme bei einem Problem nicht weiter... Und zwar habe ich ca. 60 tausend Punkte als Geokoordinaten und bekomme von einer anderen Quelle 3-x Koordinaten und ich soll alle Punkte ausgeben die in diesen Vieleck liegen.<br />
Das ganze sollte schon relativ performant funktionieren und ich habe noch keine wirkliche Idee um dies zu lösen. Meine mathematischen Fähigkeiten beschränken sich leider auch nur auf ein Leistungskurs den ich mit 12 Punkten abgeschlossen habe.</p>
<p>Ich weiß das es nicht direkt ein Problem in C++ ist aber ich habe keine Kategorie gefunden in die es besser passen könnte da ich dies mit C++ verwirklichen muss.</p>
<p>Mit freundlichen Grüßen<br />
Synonym</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2400641</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2400641</guid><dc:creator><![CDATA[Synonym]]></dc:creator><pubDate>Sat, 24 May 2014 12:36:24 GMT</pubDate></item><item><title><![CDATA[Reply to Punkte in Vieleck validieren on Sat, 24 May 2014 13:28:35 GMT]]></title><description><![CDATA[<p>Als Algorithmus kannst du dir ersteinmal <a href="http://de.wikipedia.org/wiki/Punkt-in-Polygon-Test_nach_Jordan" rel="nofollow">Punkt-in-Polygon-Test nach Jordan</a> anschauen.<br />
Evtl. könntest du auch versuchen ein umspannendes Rechteck um das Zielpolygon zu legen und dann schonmal die Punkte außerhalb des Rechtecks verwerfen, so daß dann nur noch die inneren Punkte näher betrachtet werden müssen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2400642</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2400642</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Sat, 24 May 2014 13:28:35 GMT</pubDate></item><item><title><![CDATA[Reply to Punkte in Vieleck validieren on Sat, 24 May 2014 13:48:31 GMT]]></title><description><![CDATA[<p><a href="http://de.wikipedia.org/wiki/Punkt-in-Polygon-Test_nach_Jordan" rel="nofollow">http://de.wikipedia.org/wiki/Punkt-in-Polygon-Test_nach_Jordan</a><br />
Schnell den Pseudo-Code implementiert:</p>
<pre><code>template&lt; typename T &gt;
struct Point
{
	T x, y;
};

template&lt; typename T, typename U&gt;
bool operator==( Point&lt;T&gt; const&amp; lhs, Point&lt;U&gt; const&amp; rhs )
{
	return lhs.x == rhs.x &amp;&amp; lhs.y == rhs.y;
}

template&lt; typename T &gt;
bool in_between_included( T a, T b, T c )
{
	if( a &gt; c )
		return c &lt;= b &amp;&amp; b &lt;= a;
	return a &lt;= b &amp;&amp; b &lt;= c;
}

template&lt; typename T &gt;
int sgn(T val)
{
	return (T{0} &lt; val) - (val &lt; T{0});
}

#include &lt;algorithm&gt; // std::swap

template&lt; typename T &gt;
int crossProdTest( T a, T b, T c )
{
	if( a.y == b.y &amp;&amp; b.y == c.y )
		return !in_between_included( b.x, a.x, c.x );

	if( b.y &gt; c.y )
		std::swap(b, c);

	if( a.y == b.y &amp;&amp; a.x == b.x ) return 0;
	if( a.y &lt;= b.y || a.y &gt;  c.y ) return 1;

	auto const delta = (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);

	return -1 * sgn(delta);
}

#include &lt;iterator&gt; // std::prev / std::next

template&lt; typename BidirectionalIterator,
          typename T &gt;
int pointInPolygon( BidirectionalIterator first, BidirectionalIterator last, T Q )
{
	if( first == last ) return 0;

	auto last_iter = std::prev(last);

	int t = -1 * crossProdTest( Q, *last_iter, *first );

	for(; first != last_iter; ++first )
		t *= crossProdTest( Q, *first, *std::next(first) );

	return t;
}

#include &lt;iostream&gt;

int main()
{
	// Test whether (2, 2) is in the parallelogram
	Point&lt;double&gt; points[]{ 0, 0,
	                        1, 2,
	                        0, 4,
	                        5, 2 };

	std::cout &lt;&lt; pointInPolygon( std::begin(points), std::end(points), Point&lt;double&gt;{2, 2} );
}
</code></pre>
<p>Edit^4: Und jetzt sitzt die Formattierung nicht richtig... und die Gelegenheit habe ich auch gleich genutzt um die Namensgebung anzupassen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2400644</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2400644</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sat, 24 May 2014 13:48:31 GMT</pubDate></item><item><title><![CDATA[Reply to Punkte in Vieleck validieren on Sat, 24 May 2014 14:41:08 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<p><a href="http://de.wikipedia.org/wiki/Punkt-in-Polygon-Test_nach_Jordan" rel="nofollow">http://de.wikipedia.org/wiki/Punkt-in-Polygon-Test_nach_Jordan</a><br />
Schnell den Pseudo-Code implementiert:</p>
<pre><code>template&lt; typename T &gt;
struct Point
{
	T x, y;
};

template&lt; typename T, typename U&gt;
bool operator==( Point&lt;T&gt; const&amp; lhs, Point&lt;U&gt; const&amp; rhs )
{
	return lhs.x == rhs.x &amp;&amp; lhs.y == rhs.y;
}

template&lt; typename T &gt;
bool in_between_included( T a, T b, T c )
{
	if( a &gt; c )
		return c &lt;= b &amp;&amp; b &lt;= a;
	return a &lt;= b &amp;&amp; b &lt;= c;
}

template&lt; typename T &gt;
int sgn(T val)
{
	return (T{0} &lt; val) - (val &lt; T{0});
}

#include &lt;algorithm&gt; // std::swap

template&lt; typename T &gt;
int crossProdTest( T a, T b, T c )
{
	if( a.y == b.y &amp;&amp; b.y == c.y )
		return !in_between_included( b.x, a.x, c.x );

	if( b.y &gt; c.y )
		std::swap(b, c);

	if( a.y == b.y &amp;&amp; a.x == b.x ) return 0;
	if( a.y &lt;= b.y || a.y &gt;  c.y ) return 1;

	auto const delta = (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);

	return -1 * sgn(delta);
}

#include &lt;iterator&gt; // std::prev / std::next

template&lt; typename BidirectionalIterator,
          typename T &gt;
int pointInPolygon( BidirectionalIterator first, BidirectionalIterator last, T Q )
{
	if( first == last ) return 0;

	auto last_iter = std::prev(last);

	int t = -1 * crossProdTest( Q, *last_iter, *first );

	for(; first != last_iter; ++first )
		t *= crossProdTest( Q, *first, *std::next(first) );

	return t;
}

#include &lt;iostream&gt;

int main()
{
	// Test whether (2, 2) is in the parallelogram
	Point&lt;double&gt; points[]{ 0, 0,
	                        1, 2,
	                        0, 4,
	                        5, 2 };

	std::cout &lt;&lt; pointInPolygon( std::begin(points), std::end(points), Point&lt;double&gt;{2, 2} );
}
</code></pre>
<p>Edit^4: Und jetzt sitzt die Formattierung nicht richtig... und die Gelegenheit habe ich auch gleich genutzt um die Namensgebung anzupassen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
</blockquote>
<p>Super Sache <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /> Vielen lieben dank <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /> ich freu mich wie ein Schnitzel <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /><br />
Muss das nur noch auf C++98 umschreiben und dann sollte es funktionieren <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/18594">@Th69</a> : Auch dir vielen Dank <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2400648</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2400648</guid><dc:creator><![CDATA[Synonym]]></dc:creator><pubDate>Sat, 24 May 2014 14:41:08 GMT</pubDate></item></channel></rss>