<?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[Matrizen-Transponierungs-Implentierung]]></title><description><![CDATA[<p>Hallo</p>
<p>Ich wollte nur mal fragen, ob mein Matrizen-Transponierungs-Code optimal ist.<br />
<code>this-&gt;Side</code> steht ist 4.<br />
<code>this-&gt;Array</code> ist ein <code>float*</code> der auf <code>this-&gt;Side * this-&gt;Side</code> Elemente zeigt.</p>
<pre><code class="language-cpp">Moonlight2D::Math::Matrix&amp;
Moonlight2D::Math::Matrix::Transpose(void)
{
  for(unsigned int i = 0; i &lt; this-&gt;Side * this-&gt;Side; i++)
    if(i - i % this-&gt;Side &gt; i % this-&gt;Side)
      std::swap(this-&gt;Array[i % this-&gt;Side], this-&gt;Array[i - i % this-&gt;Side]);

  return *this;
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/285285/matrizen-transponierungs-implentierung</link><generator>RSS for Node</generator><lastBuildDate>Fri, 21 Aug 2026 10:27:55 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/285285.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 17 Apr 2011 17:15:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Matrizen-Transponierungs-Implentierung on Sun, 17 Apr 2011 17:15:12 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Ich wollte nur mal fragen, ob mein Matrizen-Transponierungs-Code optimal ist.<br />
<code>this-&gt;Side</code> steht ist 4.<br />
<code>this-&gt;Array</code> ist ein <code>float*</code> der auf <code>this-&gt;Side * this-&gt;Side</code> Elemente zeigt.</p>
<pre><code class="language-cpp">Moonlight2D::Math::Matrix&amp;
Moonlight2D::Math::Matrix::Transpose(void)
{
  for(unsigned int i = 0; i &lt; this-&gt;Side * this-&gt;Side; i++)
    if(i - i % this-&gt;Side &gt; i % this-&gt;Side)
      std::swap(this-&gt;Array[i % this-&gt;Side], this-&gt;Array[i - i % this-&gt;Side]);

  return *this;
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2050669</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2050669</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Sun, 17 Apr 2011 17:15:12 GMT</pubDate></item><item><title><![CDATA[Reply to Matrizen-Transponierungs-Implentierung on Sun, 17 Apr 2011 17:24:54 GMT]]></title><description><![CDATA[<p>Nein. Optimal ist gegenüber.<br />
Das Semikolon nach der Funktion ist falsch.<br />
So viel % ist so viel lahm.<br />
Das (void) klingt nach einem urururalten C++-Buch.<br />
Wozu überhaupt transponieren? Mach doch einen Transponier-Proxy.</p>
<pre><code class="language-cpp">float&amp; Moonlight2D::Math::TransposedMatrixProxy at(size_t y,size_t x){
   retrun victim-&gt;at(x,y);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2050677</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2050677</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 17 Apr 2011 17:24:54 GMT</pubDate></item><item><title><![CDATA[Reply to Matrizen-Transponierungs-Implentierung on Sun, 17 Apr 2011 17:32:19 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>Das Semikolon nach der Funktion ist falsch.</p>
</blockquote>
<p>Eisflamme schrieb:</p>
<blockquote>
<p>ist doch nie falsch, es ist lediglich optional.</p>
</blockquote>
<p><a href="http://www.c-plusplus.net/forum/283866" rel="nofollow">Quelle</a>.</p>
<p>volkard schrieb:</p>
<blockquote>
<p>So viel % ist so viel lahm.</p>
</blockquote>
<p>Gut, werde ich in eine Variable stopfen.</p>
<p>volkard schrieb:</p>
<blockquote>
<p>Das (void) klingt nach einem urururalten C++-Buch.</p>
</blockquote>
<p>Wieso? Nur weil es überflüssig ist? Vieles ist überflüssig und wird trotzdem noch eingesetzt.</p>
<p>volkard schrieb:</p>
<blockquote>
<p>Wozu überhaupt transponieren?</p>
</blockquote>
<p>OpenGL will sie transponiert haben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2050688</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2050688</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Sun, 17 Apr 2011 17:32:19 GMT</pubDate></item><item><title><![CDATA[Reply to Matrizen-Transponierungs-Implentierung on Sun, 17 Apr 2011 17:41:46 GMT]]></title><description><![CDATA[<p>EOutOfResources schrieb:</p>
<blockquote>
<p>volkard schrieb:</p>
<blockquote>
<p>Das Semikolon nach der Funktion ist falsch.</p>
</blockquote>
<p>Eisflamme schrieb:</p>
<blockquote>
<p>ist doch nie falsch, es ist lediglich optional.</p>
</blockquote>
<p><a href="http://www.c-plusplus.net/forum/283866" rel="nofollow">Quelle</a>.</p>
</blockquote>
<p>Trotzdem ist es falsch. Da hat halt Eisflamme unrecht.</p>
<p>EOutOfResources schrieb:</p>
<blockquote>
<p>volkard schrieb:</p>
<blockquote>
<p>So viel % ist so viel lahm.</p>
</blockquote>
<p>Gut, werde ich in eine Variable stopfen.</p>
</blockquote>
<p>Finde doch mal raus, was verschachtelten Schleifen sind.</p>
<p>EOutOfResources schrieb:</p>
<blockquote>
<p>volkard schrieb:</p>
<blockquote>
<p>Das (void) klingt nach einem urururalten C++-Buch.</p>
</blockquote>
<p>Wieso? Nur weil es überflüssig ist? Vieles ist überflüssig und wird trotzdem noch eingesetzt.</p>
</blockquote>
<p>Aber so wird man Dich nie ernst nehmen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2050694</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2050694</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 17 Apr 2011 17:41:46 GMT</pubDate></item><item><title><![CDATA[Reply to Matrizen-Transponierungs-Implentierung on Sun, 17 Apr 2011 17:59:34 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>Trotzdem ist es falsch. Da hat halt Eisflamme unrecht.</p>
</blockquote>
<p>OK. Werde ich fixen.</p>
<p>volkard schrieb:</p>
<blockquote>
<p>Finde doch mal raus, was verschachtelten Schleifen sind.</p>
</blockquote>
<p>Weiss ich. Was hat das damit zu tun? Meinst du wegen der Implementierung des Modulo-Operators?</p>
<p>volkard schrieb:</p>
<blockquote>
<p>Aber so wird man Dich nie ernst nehmen.</p>
</blockquote>
<p>Grund?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2050707</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2050707</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Sun, 17 Apr 2011 17:59:34 GMT</pubDate></item><item><title><![CDATA[Reply to Matrizen-Transponierungs-Implentierung on Sun, 17 Apr 2011 18:00:38 GMT]]></title><description><![CDATA[<p>Forkst du grade mein Projekt? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_tongue"
      title=":P"
      alt="😛"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2050709</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2050709</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Sun, 17 Apr 2011 18:00:38 GMT</pubDate></item><item><title><![CDATA[Reply to Matrizen-Transponierungs-Implentierung on Sun, 17 Apr 2011 18:01:58 GMT]]></title><description><![CDATA[<p>Scorcher24 schrieb:</p>
<blockquote>
<p>Forkst du grade mein Projekt? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_tongue"
      title=":P"
      alt="😛"
    /></p>
</blockquote>
<p>Keine Ahnung was &quot;forken&quot; heisst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2050711</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2050711</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Sun, 17 Apr 2011 18:01:58 GMT</pubDate></item><item><title><![CDATA[Reply to Matrizen-Transponierungs-Implentierung on Sun, 17 Apr 2011 18:05:14 GMT]]></title><description><![CDATA[<p>EOutOfResources schrieb:</p>
<blockquote>
<p>volkard schrieb:</p>
<blockquote>
<p>Finde doch mal raus, was verschachtelten Schleifen sind.</p>
</blockquote>
<p>Weiss ich. Was hat das damit zu tun? Meinst du wegen der Implementierung des Modulo-Operators?</p>
</blockquote>
<p>Weil Du zwei Variablen in eine steckst und mit % die beiden wieder extrahierst, was erstens eine Schnapsidee ist, und zweitens das if erst notwendig macht.</p>
<p>EOutOfResources schrieb:</p>
<blockquote>
<p>volkard schrieb:</p>
<blockquote>
<p>Aber so wird man Dich nie ernst nehmen.</p>
</blockquote>
<p>Grund?</p>
</blockquote>
<p>Offen vorgetragene Lernresistenz.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2050713</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2050713</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 17 Apr 2011 18:05:14 GMT</pubDate></item><item><title><![CDATA[Reply to Matrizen-Transponierungs-Implentierung on Sun, 17 Apr 2011 18:08:59 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>Weil Du zwei Variablen in eine steckst und mit % die beiden wieder extrahierst, was erstens eine Schnapsidee ist, und zweitens das if erst notwendig macht.</p>
</blockquote>
<p>Aha, jetzt verstehe ich, was du meinst. Das <code>if</code> ist immer noch nötig, da ich sonst alles doppelt swapen würde.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2050716</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2050716</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Sun, 17 Apr 2011 18:08:59 GMT</pubDate></item><item><title><![CDATA[Reply to Matrizen-Transponierungs-Implentierung on Sun, 17 Apr 2011 18:09:41 GMT]]></title><description><![CDATA[<p>EOutOfResources schrieb:</p>
<blockquote>
<p>volkard schrieb:</p>
<blockquote>
<p>Weil Du zwei Variablen in eine steckst und mit % die beiden wieder extrahierst, was erstens eine Schnapsidee ist, und zweitens das if erst notwendig macht.</p>
</blockquote>
<p>Aha, jetzt verstehe ich, was du meinst. Das <code>if</code> ist immer noch nötig, da ich sonst alles doppelt swapen würde.</p>
</blockquote>
<p>Außer, Du denkst kurz über die innere Laufbedingung nach.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2050718</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2050718</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 17 Apr 2011 18:09:41 GMT</pubDate></item><item><title><![CDATA[Reply to Matrizen-Transponierungs-Implentierung on Sun, 17 Apr 2011 18:20:02 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>Außer, Du denkst kurz über die innere Laufbedingung nach.</p>
</blockquote>
<p>Den Satz verstehe ich überhaupt nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2050727</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2050727</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Sun, 17 Apr 2011 18:20:02 GMT</pubDate></item><item><title><![CDATA[Reply to Matrizen-Transponierungs-Implentierung on Sun, 17 Apr 2011 18:25:36 GMT]]></title><description><![CDATA[<p>EOutOfResources schrieb:</p>
<blockquote>
<p>volkard schrieb:</p>
<blockquote>
<p>Außer, Du denkst kurz über die innere Laufbedingung nach.</p>
</blockquote>
<p>Den Satz verstehe ich überhaupt nicht.</p>
</blockquote>
<p>Vorher:</p>
<pre><code class="language-cpp">for(int y=1;y!=4;++y)
  for(int x=1;x!=4;++x)
    if(x&lt;y)
      cout&lt;&lt;y&lt;&lt;' '&lt;&lt;x&lt;&lt;'\n';
</code></pre>
<p>Nachher:</p>
<pre><code class="language-cpp">for(int y=1;y!=4;++y)
  for(int x=1;x!=y;++x)
    cout&lt;&lt;y&lt;&lt;' '&lt;&lt;x&lt;&lt;'\n';
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2050732</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2050732</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 17 Apr 2011 18:25:36 GMT</pubDate></item><item><title><![CDATA[Reply to Matrizen-Transponierungs-Implentierung on Sun, 17 Apr 2011 18:40:30 GMT]]></title><description><![CDATA[<p>EDIT: Unterschied nicht bemerkt. Peinlich...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2050745</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2050745</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Sun, 17 Apr 2011 18:40:30 GMT</pubDate></item><item><title><![CDATA[Reply to Matrizen-Transponierungs-Implentierung on Sun, 17 Apr 2011 18:38:14 GMT]]></title><description><![CDATA[<p>Dann vergleich doch mal die Endbedingung von volkard mit deinem Code - siehst du den Unterschied zwischen &quot;x!=4&quot; und &quot;x!=y&quot;?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2050750</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2050750</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Sun, 17 Apr 2011 18:38:14 GMT</pubDate></item><item><title><![CDATA[Reply to Matrizen-Transponierungs-Implentierung on Sun, 17 Apr 2011 18:40:56 GMT]]></title><description><![CDATA[<p>CStoll schrieb:</p>
<blockquote>
<p>Dann vergleich doch mal die Endbedingung von volkard mit deinem Code - siehst du den Unterschied zwischen &quot;x!=4&quot; und &quot;x!=y&quot;?</p>
</blockquote>
<p>Oh mann. Habe ich übersehen. Ich nehmen alles zurück.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2050754</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2050754</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Sun, 17 Apr 2011 18:40:56 GMT</pubDate></item><item><title><![CDATA[Reply to Matrizen-Transponierungs-Implentierung on Sun, 17 Apr 2011 18:46:56 GMT]]></title><description><![CDATA[<p>in-place transponieren...</p>
<p>wenn ich so etwas schon sehe, da dreht es mir doch die Fussnägel hoch. Vor allem wenn es nur um die mickrige Dimension 4x4 geht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2050761</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2050761</guid><dc:creator><![CDATA[bmario]]></dc:creator><pubDate>Sun, 17 Apr 2011 18:46:56 GMT</pubDate></item><item><title><![CDATA[Reply to Matrizen-Transponierungs-Implentierung on Sun, 17 Apr 2011 19:01:34 GMT]]></title><description><![CDATA[<p>nur mal so kurz ins Blaue:<br />
wenn dein Array ordentlich aussehen würde, könntest du das so schreiben:</p>
<pre><code class="language-cpp">for(unsigned int i = 0; i &lt; Side-1; i++)
    for(unsigned int j = i+1; j &lt; Side; i++)
        std::swap(Array[i][j], Array[j][i]);
</code></pre>
<p>Die Diagonalelemente werden ausgespart und wir laufen nur über die obere Dreiecksmatrix.</p>
<p>nun bestehst du auf Indexfrickelei und es wird hässlich</p>
<pre><code class="language-cpp">for(unsigned int i = 0; i &lt; Side-1; i++)
    for(unsigned int j = i+1; j &lt; Side; i++)
        std::swap(Array[Side*i+j], Array[Side*j+i]);
</code></pre>
<p>ich schätze man kann da noch lustig die indizes optimieren. Aber das kann der Compiler wahrscheinlich besser...</p>
<p>//edit und ich sehe gerade, dass dein Code gar nicht macht, was er soll</p>
<pre><code class="language-cpp">std::swap(this-&gt;Array[i % this-&gt;Side], this-&gt;Array[i - i % this-&gt;Side]);
</code></pre>
<p>Side ist 4. i geht von 0 bis Side*Side. Also 16. i %Side ist also: 0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3. das erste Argument deines Swaps ist also nur die erste Zeile/Spalte deiner Matrix.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2050764</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2050764</guid><dc:creator><![CDATA[otze]]></dc:creator><pubDate>Sun, 17 Apr 2011 19:01:34 GMT</pubDate></item></channel></rss>