<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Was mir so einfällt &#187; Kaufhausschlacht</title>
	<atom:link href="http://xaedes.de/blog/category/entwicklung/kaufhausschlacht/feed/" rel="self" type="application/rss+xml" />
	<link>http://xaedes.de/blog</link>
	<description>Ich habe keine Probleme, ich hab ja Whiteboards</description>
	<lastBuildDate>Tue, 28 Jul 2015 00:20:45 +0000</lastBuildDate>
	<language>de-DE</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.35</generator>
	<item>
		<title>Schnittpunkt zweier Geraden</title>
		<link>http://xaedes.de/blog/2011/02/06/schnittpunkt-zweier-geraden/</link>
		<comments>http://xaedes.de/blog/2011/02/06/schnittpunkt-zweier-geraden/#comments</comments>
		<pubDate>Sun, 06 Feb 2011 23:19:17 +0000</pubDate>
		<dc:creator><![CDATA[xaedes]]></dc:creator>
				<category><![CDATA[Kaufhausschlacht]]></category>

		<guid isPermaLink="false">http://xaedes.de/blog/?p=661</guid>
		<description><![CDATA[Wollen wir den Schnittpunkt zweier Geraden bestimmen bestimmt setzen wir die beide Geradengleichungen gleich: Jetzt müssen wir nach oder umstellen und in die entsprechende Parametergleichung einsetzen um einen Schnittpunkt zu errechnen: Fall : Fall : Schnittpunkt berechnet. Fall : Fall: Geraden 1 und 2 sind parallel, schneiden sich also nicht. Fall: Gerade 2 hat keine [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Wollen wir den Schnittpunkt zweier Geraden bestimmen bestimmt setzen wir die beide Geradengleichungen gleich:<br />
<img src='http://s0.wp.com/latex.php?latex=++%5Coverrightarrow%7Bx_1%7D+%3D+%5Coverrightarrow%7Bs_1%7D+%2B+k+%5Ccdot+%5Coverrightarrow%7Bv_1%7D+%5C%5C++%5Coverrightarrow%7Bx_2%7D+%3D+%5Coverrightarrow%7Bs_2%7D+%2B+m+%5Ccdot+%5Coverrightarrow%7Bv_2%7D+%5C%5C++%5C%5C++%5Coverrightarrow%7Bx_1%7D+%3D+%5Coverrightarrow%7Bx_2%7D+%5C%5C++%5Coverrightarrow%7Bs_1%7D+%2B+k+%5Ccdot+%5Coverrightarrow%7Bv_1%7D+%3D+%5Coverrightarrow%7Bs_2%7D+%2B+m+%5Ccdot+%5Coverrightarrow%7Bv_2%7D+%5C%5C++&#038;bg=ffffff&#038;fg=000000&#038;s=2' alt='  \overrightarrow{x_1} = \overrightarrow{s_1} + k \cdot \overrightarrow{v_1} \\  \overrightarrow{x_2} = \overrightarrow{s_2} + m \cdot \overrightarrow{v_2} \\  \\  \overrightarrow{x_1} = \overrightarrow{x_2} \\  \overrightarrow{s_1} + k \cdot \overrightarrow{v_1} = \overrightarrow{s_2} + m \cdot \overrightarrow{v_2} \\  ' title='  \overrightarrow{x_1} = \overrightarrow{s_1} + k \cdot \overrightarrow{v_1} \\  \overrightarrow{x_2} = \overrightarrow{s_2} + m \cdot \overrightarrow{v_2} \\  \\  \overrightarrow{x_1} = \overrightarrow{x_2} \\  \overrightarrow{s_1} + k \cdot \overrightarrow{v_1} = \overrightarrow{s_2} + m \cdot \overrightarrow{v_2} \\  ' class='latex' /></p>
<p>Jetzt müssen wir nach <img src='http://s0.wp.com/latex.php?latex=k&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='k' title='k' class='latex' /> oder <img src='http://s0.wp.com/latex.php?latex=m&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='m' title='m' class='latex' /> umstellen und in die entsprechende Parametergleichung einsetzen um einen Schnittpunkt zu errechnen:<br />
<img src='http://s0.wp.com/latex.php?latex=++%5Coverrightarrow%7Bs_1%7D+%2B+k+%5Ccdot+%5Coverrightarrow%7Bv_1%7D+%3D+%5Coverrightarrow%7Bs_2%7D+%2B+m+%5Ccdot+%5Coverrightarrow%7Bv_2%7D+%5C%5C++%5Coverrightarrow%7Bs_1%7D.x+%2B+k+%5Ccdot+%5Coverrightarrow%7Bv_1%7D.x+%3D+%5Coverrightarrow%7Bs_2%7D.x+%2B+m+%5Ccdot+%5Coverrightarrow%7Bv_2%7D.x+%5C%5C++&#038;bg=ffffff&#038;fg=000000&#038;s=2' alt='  \overrightarrow{s_1} + k \cdot \overrightarrow{v_1} = \overrightarrow{s_2} + m \cdot \overrightarrow{v_2} \\  \overrightarrow{s_1}.x + k \cdot \overrightarrow{v_1}.x = \overrightarrow{s_2}.x + m \cdot \overrightarrow{v_2}.x \\  ' title='  \overrightarrow{s_1} + k \cdot \overrightarrow{v_1} = \overrightarrow{s_2} + m \cdot \overrightarrow{v_2} \\  \overrightarrow{s_1}.x + k \cdot \overrightarrow{v_1}.x = \overrightarrow{s_2}.x + m \cdot \overrightarrow{v_2}.x \\  ' class='latex' /></p>
<ol>
<li>Fall : <img src='http://s0.wp.com/latex.php?latex=+%5Coverrightarrow%7Bv_1%7D.x+%5Cneq+0+&#038;bg=ffffff&#038;fg=000000&#038;s=2' alt=' \overrightarrow{v_1}.x \neq 0 ' title=' \overrightarrow{v_1}.x \neq 0 ' class='latex' /><br />
<img src='http://s0.wp.com/latex.php?latex=++k+%3D+%5Cfrac%7B%5Coverrightarrow%7Bs_2%7D.x+%2B+m+%5Ccdot+%5Coverrightarrow%7Bv_2%7D.x-%5Coverrightarrow%7Bs_1%7D.x%7D%7B%5Coverrightarrow%7Bv_1%7D.x%7D+%5C%5C++%5Coverrightarrow%7Bs_1%7D.y+%2B+k+%5Ccdot+%5Coverrightarrow%7Bv_1%7D.y+%3D+%5Coverrightarrow%7Bs_2%7D.y+%2B+m+%5Ccdot+%5Coverrightarrow%7Bv_2%7D.y+%5C%5C++%5Coverrightarrow%7Bs_1%7D.y+%2B+%5Cfrac%7B%5Coverrightarrow%7Bs_2%7D.x+%2B+m+%5Ccdot+%5Coverrightarrow%7Bv_2%7D.x-%5Coverrightarrow%7Bs_1%7D.x%7D%7B%5Coverrightarrow%7Bv_1%7D.x%7D+%5Ccdot+%5Coverrightarrow%7Bv_1%7D.y+%3D+%5Coverrightarrow%7Bs_2%7D.y+%2B+m+%5Ccdot+%5Coverrightarrow%7Bv_2%7D.y+%5C%5C++%5Coverrightarrow%7Bs_1%7D.y+%2B+%5Cfrac%7B%28%5Coverrightarrow%7Bs_2%7D.x-%5Coverrightarrow%7Bs_1%7D.x%29+%5Ccdot+%5Coverrightarrow%7Bv_1%7D.y+%7D%7B%5Coverrightarrow%7Bv_1%7D.x%7D+%2B+m+%5Ccdot+%5Cfrac%7B%5Coverrightarrow%7Bv_2%7D.x+%5Ccdot+%5Coverrightarrow%7Bv_1%7D.y%7D%7B%5Coverrightarrow%7Bv_1%7D.x%7D+%3D+%5Coverrightarrow%7Bs_2%7D.y+%2B+m+%5Ccdot+%5Coverrightarrow%7Bv_2%7D.y+%5C%5C++m+%5Ccdot+%28%5Cfrac%7B%5Coverrightarrow%7Bv_2%7D.x+%5Ccdot+%5Coverrightarrow%7Bv_1%7D.y%7D%7B%5Coverrightarrow%7Bv_1%7D.x%7D+-+%5Coverrightarrow%7Bv_2%7D.y%29+%3D++%5Coverrightarrow%7Bs_2%7D.y+-+%5Coverrightarrow%7Bs_1%7D.y+-+%5Cfrac%7B%28%5Coverrightarrow%7Bs_2%7D.x-%5Coverrightarrow%7Bs_1%7D.x%29+%5Ccdot+%5Coverrightarrow%7Bv_1%7D.y+%7D%7B%5Coverrightarrow%7Bv_1%7D.x%7D++&#038;bg=ffffff&#038;fg=000000&#038;s=2' alt='  k = \frac{\overrightarrow{s_2}.x + m \cdot \overrightarrow{v_2}.x-\overrightarrow{s_1}.x}{\overrightarrow{v_1}.x} \\  \overrightarrow{s_1}.y + k \cdot \overrightarrow{v_1}.y = \overrightarrow{s_2}.y + m \cdot \overrightarrow{v_2}.y \\  \overrightarrow{s_1}.y + \frac{\overrightarrow{s_2}.x + m \cdot \overrightarrow{v_2}.x-\overrightarrow{s_1}.x}{\overrightarrow{v_1}.x} \cdot \overrightarrow{v_1}.y = \overrightarrow{s_2}.y + m \cdot \overrightarrow{v_2}.y \\  \overrightarrow{s_1}.y + \frac{(\overrightarrow{s_2}.x-\overrightarrow{s_1}.x) \cdot \overrightarrow{v_1}.y }{\overrightarrow{v_1}.x} + m \cdot \frac{\overrightarrow{v_2}.x \cdot \overrightarrow{v_1}.y}{\overrightarrow{v_1}.x} = \overrightarrow{s_2}.y + m \cdot \overrightarrow{v_2}.y \\  m \cdot (\frac{\overrightarrow{v_2}.x \cdot \overrightarrow{v_1}.y}{\overrightarrow{v_1}.x} - \overrightarrow{v_2}.y) =  \overrightarrow{s_2}.y - \overrightarrow{s_1}.y - \frac{(\overrightarrow{s_2}.x-\overrightarrow{s_1}.x) \cdot \overrightarrow{v_1}.y }{\overrightarrow{v_1}.x}  ' title='  k = \frac{\overrightarrow{s_2}.x + m \cdot \overrightarrow{v_2}.x-\overrightarrow{s_1}.x}{\overrightarrow{v_1}.x} \\  \overrightarrow{s_1}.y + k \cdot \overrightarrow{v_1}.y = \overrightarrow{s_2}.y + m \cdot \overrightarrow{v_2}.y \\  \overrightarrow{s_1}.y + \frac{\overrightarrow{s_2}.x + m \cdot \overrightarrow{v_2}.x-\overrightarrow{s_1}.x}{\overrightarrow{v_1}.x} \cdot \overrightarrow{v_1}.y = \overrightarrow{s_2}.y + m \cdot \overrightarrow{v_2}.y \\  \overrightarrow{s_1}.y + \frac{(\overrightarrow{s_2}.x-\overrightarrow{s_1}.x) \cdot \overrightarrow{v_1}.y }{\overrightarrow{v_1}.x} + m \cdot \frac{\overrightarrow{v_2}.x \cdot \overrightarrow{v_1}.y}{\overrightarrow{v_1}.x} = \overrightarrow{s_2}.y + m \cdot \overrightarrow{v_2}.y \\  m \cdot (\frac{\overrightarrow{v_2}.x \cdot \overrightarrow{v_1}.y}{\overrightarrow{v_1}.x} - \overrightarrow{v_2}.y) =  \overrightarrow{s_2}.y - \overrightarrow{s_1}.y - \frac{(\overrightarrow{s_2}.x-\overrightarrow{s_1}.x) \cdot \overrightarrow{v_1}.y }{\overrightarrow{v_1}.x}  ' class='latex' /></p>
<ol>
<li>Fall : <img src='http://s0.wp.com/latex.php?latex=+%5Cfrac%7B%5Coverrightarrow%7Bv_2%7D.x+%5Ccdot+%5Coverrightarrow%7Bv_1%7D.y%7D%7B%5Coverrightarrow%7Bv_1%7D.x%7D+-+%5Coverrightarrow%7Bv_2%7D.y+%5Cneq+0+&#038;bg=ffffff&#038;fg=000000&#038;s=2' alt=' \frac{\overrightarrow{v_2}.x \cdot \overrightarrow{v_1}.y}{\overrightarrow{v_1}.x} - \overrightarrow{v_2}.y \neq 0 ' title=' \frac{\overrightarrow{v_2}.x \cdot \overrightarrow{v_1}.y}{\overrightarrow{v_1}.x} - \overrightarrow{v_2}.y \neq 0 ' class='latex' /><br />
<img src='http://s0.wp.com/latex.php?latex=++m+%3D+%5Cfrac%7B%5Coverrightarrow%7Bs_2%7D.y+-+%5Coverrightarrow%7Bs_1%7D.y+-+%5Cfrac%7B%28%5Coverrightarrow%7Bs_2%7D.x-%5Coverrightarrow%7Bs_1%7D.x%29+%5Ccdot+%5Coverrightarrow%7Bv_1%7D.y+%7D%7B%5Coverrightarrow%7Bv_1%7D.x%7D%7D%7B%5Cfrac%7B%5Coverrightarrow%7Bv_2%7D.x+%5Ccdot+%5Coverrightarrow%7Bv_1%7D.y%7D%7B%5Coverrightarrow%7Bv_1%7D.x%7D+-+%5Coverrightarrow%7Bv_2%7D.y%7D+%5C%5C++%5C%5C++%5Coverrightarrow%7Bx_2%7D+%3D+%5Coverrightarrow%7Bs_2%7D+%2B+m+%5Ccdot+%5Coverrightarrow%7Bv_2%7D%5C%5C++&#038;bg=ffffff&#038;fg=000000&#038;s=2' alt='  m = \frac{\overrightarrow{s_2}.y - \overrightarrow{s_1}.y - \frac{(\overrightarrow{s_2}.x-\overrightarrow{s_1}.x) \cdot \overrightarrow{v_1}.y }{\overrightarrow{v_1}.x}}{\frac{\overrightarrow{v_2}.x \cdot \overrightarrow{v_1}.y}{\overrightarrow{v_1}.x} - \overrightarrow{v_2}.y} \\  \\  \overrightarrow{x_2} = \overrightarrow{s_2} + m \cdot \overrightarrow{v_2}\\  ' title='  m = \frac{\overrightarrow{s_2}.y - \overrightarrow{s_1}.y - \frac{(\overrightarrow{s_2}.x-\overrightarrow{s_1}.x) \cdot \overrightarrow{v_1}.y }{\overrightarrow{v_1}.x}}{\frac{\overrightarrow{v_2}.x \cdot \overrightarrow{v_1}.y}{\overrightarrow{v_1}.x} - \overrightarrow{v_2}.y} \\  \\  \overrightarrow{x_2} = \overrightarrow{s_2} + m \cdot \overrightarrow{v_2}\\  ' class='latex' /><br />
<strong>Schnittpunkt <img src='http://s0.wp.com/latex.php?latex=x_2&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x_2' title='x_2' class='latex' /> berechnet.</strong>
</li>
<li>Fall : <img src='http://s0.wp.com/latex.php?latex=+%5Cfrac%7B%5Coverrightarrow%7Bv_2%7D.x+%5Ccdot+%5Coverrightarrow%7Bv_1%7D.y%7D%7B%5Coverrightarrow%7Bv_1%7D.x%7D+-+%5Coverrightarrow%7Bv_2%7D.y+%3D+0+&#038;bg=ffffff&#038;fg=000000&#038;s=2' alt=' \frac{\overrightarrow{v_2}.x \cdot \overrightarrow{v_1}.y}{\overrightarrow{v_1}.x} - \overrightarrow{v_2}.y = 0 ' title=' \frac{\overrightarrow{v_2}.x \cdot \overrightarrow{v_1}.y}{\overrightarrow{v_1}.x} - \overrightarrow{v_2}.y = 0 ' class='latex' /><br />
<img src='http://s0.wp.com/latex.php?latex=+%5Cfrac%7B%5Coverrightarrow%7Bv_2%7D.x+%5Ccdot+%5Coverrightarrow%7Bv_1%7D.y%7D%7B%5Coverrightarrow%7Bv_1%7D.x%7D+%3D+%5Coverrightarrow%7Bv_2%7D.y&#038;bg=ffffff&#038;fg=000000&#038;s=2' alt=' \frac{\overrightarrow{v_2}.x \cdot \overrightarrow{v_1}.y}{\overrightarrow{v_1}.x} = \overrightarrow{v_2}.y' title=' \frac{\overrightarrow{v_2}.x \cdot \overrightarrow{v_1}.y}{\overrightarrow{v_1}.x} = \overrightarrow{v_2}.y' class='latex' /></p>
<ol>
<li>Fall: <img src='http://s0.wp.com/latex.php?latex=+%5Coverrightarrow%7Bv_2%7D.x+%5Cneq+0+&#038;bg=ffffff&#038;fg=000000&#038;s=2' alt=' \overrightarrow{v_2}.x \neq 0 ' title=' \overrightarrow{v_2}.x \neq 0 ' class='latex' /><br />
<img src='http://s0.wp.com/latex.php?latex=+%5Cfrac%7B+%5Coverrightarrow%7Bv_1%7D.y%7D%7B%5Coverrightarrow%7Bv_1%7D.x%7D+%3D+%5Cfrac%7B%5Coverrightarrow%7Bv_2%7D.y%7D%7B%5Coverrightarrow%7Bv_2%7D.x%7D&#038;bg=ffffff&#038;fg=000000&#038;s=2' alt=' \frac{ \overrightarrow{v_1}.y}{\overrightarrow{v_1}.x} = \frac{\overrightarrow{v_2}.y}{\overrightarrow{v_2}.x}' title=' \frac{ \overrightarrow{v_1}.y}{\overrightarrow{v_1}.x} = \frac{\overrightarrow{v_2}.y}{\overrightarrow{v_2}.x}' class='latex' /><br />
Geraden 1 und 2 sind parallel, <strong>schneiden sich also nicht</strong>.
</li>
<li>Fall: <img src='http://s0.wp.com/latex.php?latex=+%5Coverrightarrow%7Bv_2%7D.x+%3D+0+&#038;bg=ffffff&#038;fg=000000&#038;s=2' alt=' \overrightarrow{v_2}.x = 0 ' title=' \overrightarrow{v_2}.x = 0 ' class='latex' /><br />
<img src='http://s0.wp.com/latex.php?latex=+%5Cfrac%7B0+%5Ccdot+%5Coverrightarrow%7Bv_1%7D.y%7D%7B%5Coverrightarrow%7Bv_1%7D.x%7D+%3D+%5Coverrightarrow%7Bv_2%7D.y+%5C%5C++%5Coverrightarrow%7Bv_2%7D.x+%3D+%5Coverrightarrow%7Bv_2%7D.y+%3D+0&#038;bg=ffffff&#038;fg=000000&#038;s=2' alt=' \frac{0 \cdot \overrightarrow{v_1}.y}{\overrightarrow{v_1}.x} = \overrightarrow{v_2}.y \\  \overrightarrow{v_2}.x = \overrightarrow{v_2}.y = 0' title=' \frac{0 \cdot \overrightarrow{v_1}.y}{\overrightarrow{v_1}.x} = \overrightarrow{v_2}.y \\  \overrightarrow{v_2}.x = \overrightarrow{v_2}.y = 0' class='latex' /><br />
Gerade 2 hat keine Richtung, Geraden <strong>schneiden sich also nicht</strong>.
</li>
</ol>
</li>
</ol>
</li>
<li>Fall : <img src='http://s0.wp.com/latex.php?latex=+%5Coverrightarrow%7Bv_1%7D.x+%3D+0+&#038;bg=ffffff&#038;fg=000000&#038;s=2' alt=' \overrightarrow{v_1}.x = 0 ' title=' \overrightarrow{v_1}.x = 0 ' class='latex' /><br />
<img src='http://s0.wp.com/latex.php?latex=++%5Coverrightarrow%7Bs_1%7D.x+%2B+k+%5Ccdot+0+%3D+%5Coverrightarrow%7Bs_2%7D.x+%2B+m+%5Ccdot+%5Coverrightarrow%7Bv_2%7D.x+%5C%5C++%5Coverrightarrow%7Bs_1%7D.x+%3D+%5Coverrightarrow%7Bs_2%7D.x+%2B+m+%5Ccdot+%5Coverrightarrow%7Bv_2%7D.x+%5C%5C++&#038;bg=ffffff&#038;fg=000000&#038;s=2' alt='  \overrightarrow{s_1}.x + k \cdot 0 = \overrightarrow{s_2}.x + m \cdot \overrightarrow{v_2}.x \\  \overrightarrow{s_1}.x = \overrightarrow{s_2}.x + m \cdot \overrightarrow{v_2}.x \\  ' title='  \overrightarrow{s_1}.x + k \cdot 0 = \overrightarrow{s_2}.x + m \cdot \overrightarrow{v_2}.x \\  \overrightarrow{s_1}.x = \overrightarrow{s_2}.x + m \cdot \overrightarrow{v_2}.x \\  ' class='latex' /></p>
<ol>
<li>Fall: <img src='http://s0.wp.com/latex.php?latex=+%5Coverrightarrow%7Bv_2%7D.x+%5Cneq+0+&#038;bg=ffffff&#038;fg=000000&#038;s=2' alt=' \overrightarrow{v_2}.x \neq 0 ' title=' \overrightarrow{v_2}.x \neq 0 ' class='latex' /><br />
<img src='http://s0.wp.com/latex.php?latex=++m%3D%5Cfrac%7B%5Coverrightarrow%7Bs_1%7D.x-%5Coverrightarrow%7Bs_2%7D.x%7D%7B%5Coverrightarrow%7Bv_2%7D.x%7D+%5C%5C++%5Coverrightarrow%7Bx_2%7D+%3D+%5Coverrightarrow%7Bs_2%7D+%2B+m+%5Ccdot+%5Coverrightarrow%7Bv_2%7D%5C%5C++&#038;bg=ffffff&#038;fg=000000&#038;s=2' alt='  m=\frac{\overrightarrow{s_1}.x-\overrightarrow{s_2}.x}{\overrightarrow{v_2}.x} \\  \overrightarrow{x_2} = \overrightarrow{s_2} + m \cdot \overrightarrow{v_2}\\  ' title='  m=\frac{\overrightarrow{s_1}.x-\overrightarrow{s_2}.x}{\overrightarrow{v_2}.x} \\  \overrightarrow{x_2} = \overrightarrow{s_2} + m \cdot \overrightarrow{v_2}\\  ' class='latex' /><br />
<strong>Schnittpunkt <img src='http://s0.wp.com/latex.php?latex=x_2&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x_2' title='x_2' class='latex' /> berechnet.</strong>
</li>
<li>Fall: <img src='http://s0.wp.com/latex.php?latex=+%5Coverrightarrow%7Bv_2%7D.x+%3D+0+&#038;bg=ffffff&#038;fg=000000&#038;s=2' alt=' \overrightarrow{v_2}.x = 0 ' title=' \overrightarrow{v_2}.x = 0 ' class='latex' /><br />
<img src='http://s0.wp.com/latex.php?latex=+%5Coverrightarrow%7Bv_2%7D.y+%3D+%5Coverrightarrow%7Bv_1%7D.x+%3D+0+&#038;bg=ffffff&#038;fg=000000&#038;s=2' alt=' \overrightarrow{v_2}.y = \overrightarrow{v_1}.x = 0 ' title=' \overrightarrow{v_2}.y = \overrightarrow{v_1}.x = 0 ' class='latex' /><br />
Gerade 1 und 2 sind parallel, <strong>schneiden sich also nicht</strong>.
</li>
</ol>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://xaedes.de/blog/2011/02/06/schnittpunkt-zweier-geraden/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bewegung mit Kollisionserkennung Teil 3 &#8211; Demonstrationsprogramm</title>
		<link>http://xaedes.de/blog/2011/02/06/bewegung-mit-kollisionserkennung-teil-3-demo/</link>
		<comments>http://xaedes.de/blog/2011/02/06/bewegung-mit-kollisionserkennung-teil-3-demo/#comments</comments>
		<pubDate>Sun, 06 Feb 2011 20:14:13 +0000</pubDate>
		<dc:creator><![CDATA[xaedes]]></dc:creator>
				<category><![CDATA[Kaufhausschlacht]]></category>

		<guid isPermaLink="false">http://xaedes.de/blog/?p=632</guid>
		<description><![CDATA[Teil 1 &#8211; Einführung Teil 2 &#8211; Kollision mit Gerade Teil 2 &#8211; Kollision mit Gerade &#8211; Demoprogramm Teil 3 &#8211; Kollision mit Strecke Teil 3 &#8211; Kollision mit Strecke &#8211; Demoprogramm Zur Demonstration der bisherigen Lösung habe ich ein kleines Programm geschrieben, in welchem man sich die berechnete Lösung für beliebe Ausgangssituationen anzeigen lassen [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><a href="http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-1/">Teil 1 &#8211; Einführung</a><br />
<a href="http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-2/">Teil 2 &#8211; Kollision mit Gerade</a><br />
<a href="http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-2-demo/">Teil 2 &#8211; Kollision mit Gerade &#8211;  Demoprogramm</a><br />
<a href="http://xaedes.de/blog/2011/02/06/bewegung-mit-kollisionserkennung-teil-3/">Teil 3 &#8211; Kollision mit Strecke</a><br />
<a href="http://xaedes.de/blog/2011/02/06/bewegung-mit-kollisionserkennung-teil-3-demo/"><strong>Teil 3 &#8211; Kollision mit Strecke &#8211;  Demoprogramm</strong></a></p>
<p>Zur Demonstration der bisherigen Lösung habe ich ein kleines Programm geschrieben, in welchem man sich die berechnete Lösung für beliebe Ausgangssituationen anzeigen lassen kann. Man sieht, dass nicht wirklich vorhandene Kollisionen nun nicht mehr fälschlicherweise &#8222;korrigiert&#8220; werden.<br />
Screenshot:<br />
<img src="http://xaedes.de/blog/wp-content/uploads/Bildschirmfoto4-300x182.png" alt="" title="Bildschirmfoto4" width="300" height="182" class="alignnone size-medium wp-image-645" /></p>
<p>Bedienung :<br />
Linke Maustaste, Drag&#038;Drop : roter und schwarzer Kreis, Enden der schwarzen Linie<br />
Rechte Maustaste, Drag&#038;Drop : Bildschirmausschnitt<br />
Mausrad : Zoomen</p>
<p>Ausprobieren: <a href='http://xaedes.de/blog/wp-content/uploads/win-06.02.2011-21.09.zip'>win-06.02.2011-21.09</a></p>
<p>Relevante Quellcodeausschnitte:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">bool</span> TestBoundedMovement<span style="color: #008080;">::</span><span style="color: #007788;">DoLineSegmentsIntersect</span><span style="color: #008000;">&#40;</span> sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> s1, sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> e1, 
	sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> s2, sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> e2 <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> v1 <span style="color: #000080;">=</span> e1 <span style="color: #000040;">-</span> s1<span style="color: #008080;">;</span>
	sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> v2 <span style="color: #000080;">=</span> e2 <span style="color: #000040;">-</span> s2<span style="color: #008080;">;</span>
	sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> intersection<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> LinesIntersection<span style="color: #008000;">&#40;</span> s1, v1, s2, v2, intersection <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">float</span> k <span style="color: #000080;">=</span> LineParam<span style="color: #008000;">&#40;</span> s1, v1, intersection <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">float</span> m <span style="color: #000080;">=</span> LineParam<span style="color: #008000;">&#40;</span> s2, v2, intersection <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#40;</span> m <span style="color: #000080;">&gt;=</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span> m <span style="color: #000080;">&lt;=</span> <span style="color: #0000dd;">1</span> <span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;&amp;</span>
			<span style="color: #008000;">&#40;</span> k <span style="color: #000080;">&gt;=</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span> k <span style="color: #000080;">&lt;=</span> <span style="color: #0000dd;">1</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>  <span style="color: #0000ff;">else</span> 
		<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">bool</span> TestBoundedMovement<span style="color: #008080;">::</span><span style="color: #007788;">LinesIntersection</span><span style="color: #008000;">&#40;</span> sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> s1, sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> v1, 
	sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> s2, sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> v2, sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> <span style="color: #000040;">&amp;</span>intersection <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> v1.<span style="color: #007788;">x</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">float</span> a <span style="color: #000080;">=</span> v2.<span style="color: #007788;">x</span> <span style="color: #000040;">*</span> v1.<span style="color: #007788;">y</span> <span style="color: #000040;">/</span> v1.<span style="color: #007788;">x</span> <span style="color: #000040;">-</span> v2.<span style="color: #007788;">y</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> a <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">float</span> m <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span> s2.<span style="color: #007788;">y</span> <span style="color: #000040;">-</span> s1.<span style="color: #007788;">y</span> <span style="color: #000040;">-</span> <span style="color: #008000;">&#40;</span> s2.<span style="color: #007788;">x</span> <span style="color: #000040;">-</span> s1.<span style="color: #007788;">x</span> <span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span> v1.<span style="color: #007788;">y</span> <span style="color: #000040;">/</span> v1.<span style="color: #007788;">x</span> <span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> a<span style="color: #008080;">;</span>
			intersection.<span style="color: #007788;">x</span> <span style="color: #000080;">=</span> s2.<span style="color: #007788;">x</span> <span style="color: #000040;">+</span> m <span style="color: #000040;">*</span> v2.<span style="color: #007788;">x</span><span style="color: #008080;">;</span>
			intersection.<span style="color: #007788;">y</span> <span style="color: #000080;">=</span> s2.<span style="color: #007788;">y</span> <span style="color: #000040;">+</span> m <span style="color: #000040;">*</span> v2.<span style="color: #007788;">y</span><span style="color: #008080;">;</span>
			<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> v2.<span style="color: #007788;">x</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">float</span> m <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span> s1.<span style="color: #007788;">x</span> <span style="color: #000040;">-</span> s2.<span style="color: #007788;">x</span> <span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> v2.<span style="color: #007788;">x</span><span style="color: #008080;">;</span>
			intersection.<span style="color: #007788;">x</span> <span style="color: #000080;">=</span> s2.<span style="color: #007788;">x</span> <span style="color: #000040;">+</span> m <span style="color: #000040;">*</span> v2.<span style="color: #007788;">x</span><span style="color: #008080;">;</span>
			intersection.<span style="color: #007788;">y</span> <span style="color: #000080;">=</span> s2.<span style="color: #007788;">y</span> <span style="color: #000040;">+</span> m <span style="color: #000040;">*</span> v2.<span style="color: #007788;">y</span><span style="color: #008080;">;</span>
			<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">float</span> TestBoundedMovement<span style="color: #008080;">::</span><span style="color: #007788;">LineParam</span><span style="color: #008000;">&#40;</span> sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> s, sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> v, sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> p <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">float</span> k <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> v.<span style="color: #007788;">y</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		k <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>p.<span style="color: #007788;">y</span> <span style="color: #000040;">-</span> s.<span style="color: #007788;">y</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> v.<span style="color: #007788;">y</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> v.<span style="color: #007788;">x</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		k <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>p.<span style="color: #007788;">x</span> <span style="color: #000040;">-</span> s.<span style="color: #007788;">x</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> v.<span style="color: #007788;">x</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">return</span> k <span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">void</span> TestBoundedMovement<span style="color: #008080;">::</span><span style="color: #007788;">UpdateCorrectDest</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> s <span style="color: #000080;">=</span> myCircleStart.<span style="color: #007788;">GetPosition</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> v <span style="color: #000080;">=</span> myVector<span style="color: #008080;">;</span>
	sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> pl1 <span style="color: #000080;">=</span> myLineBound.<span style="color: #007788;">GetP1</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> pl2 <span style="color: #000080;">=</span> myLineBound.<span style="color: #007788;">GetP2</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> z <span style="color: #000080;">=</span> s <span style="color: #000040;">+</span> v<span style="color: #008080;">;</span>
&nbsp;
	sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> ng0<span style="color: #008080;">;</span>
	sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> nh0<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> MathUtils<span style="color: #008080;">::</span><span style="color: #007788;">VectorLen</span><span style="color: #008000;">&#40;</span>v<span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		myCircleCorrectDest.<span style="color: #007788;">SetPosition</span><span style="color: #008000;">&#40;</span> z <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">return</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> v0 <span style="color: #000080;">=</span> v <span style="color: #000040;">/</span> MathUtils<span style="color: #008080;">::</span><span style="color: #007788;">VectorLen</span><span style="color: #008000;">&#40;</span>v<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> MathUtils<span style="color: #008080;">::</span><span style="color: #007788;">ComputeNormal</span><span style="color: #008000;">&#40;</span> pl1, pl2, ng0 <span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;&amp;</span>
		 MathUtils<span style="color: #008080;">::</span><span style="color: #007788;">ComputeNormal</span><span style="color: #008000;">&#40;</span> s, z, nh0 <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
&nbsp;
		<span style="color: #0000ff;">float</span> r <span style="color: #000080;">=</span> radius<span style="color: #008080;">;</span>
&nbsp;
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> <span style="color: #000040;">!</span> DoLineSegmentsIntersect<span style="color: #008000;">&#40;</span> s <span style="color: #000040;">+</span> nh0 <span style="color: #000040;">*</span> r, 
		                               z <span style="color: #000040;">+</span> v0 <span style="color: #000040;">*</span> r <span style="color: #000040;">+</span> nh0 <span style="color: #000040;">*</span> r, 
		                               pl1, pl2 <span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;&amp;</span>
		    <span style="color: #000040;">!</span> DoLineSegmentsIntersect<span style="color: #008000;">&#40;</span> s <span style="color: #000040;">-</span> nh0 <span style="color: #000040;">*</span> r, 
		                               z <span style="color: #000040;">+</span> v0 <span style="color: #000040;">*</span> r <span style="color: #000040;">-</span> nh0 <span style="color: #000040;">*</span> r, 
		                               pl1, pl2 <span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;&amp;</span>
		    <span style="color: #000040;">!</span> DoLineSegmentsIntersect<span style="color: #008000;">&#40;</span> z <span style="color: #000040;">+</span> v0 <span style="color: #000040;">*</span> r <span style="color: #000040;">+</span> nh0 <span style="color: #000040;">*</span> r, 
		                               z <span style="color: #000040;">+</span> v0 <span style="color: #000040;">*</span> r <span style="color: #000040;">-</span> nh0 <span style="color: #000040;">*</span> r, 
		                               pl1, pl2 <span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #666666;">//Bewegungslinie und BoundLine überschneiden sich nicht,</span>
			<span style="color: #666666;">//also wird keine Kollisionserkennung vorgenommen,</span>
			<span style="color: #666666;">//also ist myCircleCorrectDest = myCircleDest</span>
			myCircleCorrectDest.<span style="color: #007788;">SetPosition</span><span style="color: #008000;">&#40;</span> z <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			<span style="color: #0000ff;">return</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> MathUtils<span style="color: #008080;">::</span><span style="color: #007788;">DotProduct</span><span style="color: #008000;">&#40;</span> v, ng0 <span style="color: #008000;">&#41;</span> <span style="color: #000080;">&gt;</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #666666;">//Bewegungsvektor zeigt von BoundingLine weg,</span>
			<span style="color: #666666;">//also wird keine Kollisionserkennung vorgenommen,</span>
			<span style="color: #666666;">//also ist myCircleCorrectDest = myCircleDest</span>
			myCircleCorrectDest.<span style="color: #007788;">SetPosition</span><span style="color: #008000;">&#40;</span> z <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			<span style="color: #0000ff;">return</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> MathUtils<span style="color: #008080;">::</span><span style="color: #007788;">DotProduct</span><span style="color: #008000;">&#40;</span> s <span style="color: #000040;">-</span> pl2, ng0 <span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #666666;">//Der Startpunkt liegt hinter der Line</span>
			<span style="color: #666666;">//also wird keine Kollisionserkennung vorgenommen,</span>
			<span style="color: #666666;">//also ist myCircleCorrectDest = myCircleDest</span>
			myCircleCorrectDest.<span style="color: #007788;">SetPosition</span><span style="color: #008000;">&#40;</span> z <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			<span style="color: #0000ff;">return</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #0000ff;">float</span> d <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span> MathUtils<span style="color: #008080;">::</span><span style="color: #007788;">DotProduct</span><span style="color: #008000;">&#40;</span> z <span style="color: #000040;">-</span> pl2, ng0 <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> d <span style="color: #000080;">&gt;=</span> r <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #666666;">//Es findet gar keine Kollision statt</span>
			<span style="color: #666666;">//also ist myCircleCorrectDest = myCircleDest</span>
			myCircleCorrectDest.<span style="color: #007788;">SetPosition</span><span style="color: #008000;">&#40;</span> z <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			<span style="color: #0000ff;">return</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #0000ff;">float</span> cosAlpha <span style="color: #000080;">=</span> MathUtils<span style="color: #008080;">::</span><span style="color: #007788;">DotProduct</span><span style="color: #008000;">&#40;</span> v, pl2 <span style="color: #000040;">-</span> pl1 <span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> 
				<span style="color: #008000;">&#40;</span> MathUtils<span style="color: #008080;">::</span><span style="color: #007788;">VectorLen</span><span style="color: #008000;">&#40;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span>  
				  MathUtils<span style="color: #008080;">::</span><span style="color: #007788;">VectorLen</span><span style="color: #008000;">&#40;</span> pl2 <span style="color: #000040;">-</span> pl1 <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
&nbsp;
		<span style="color: #0000ff;">float</span> sinAlpha <span style="color: #000080;">=</span> <span style="color: #0000dd;">sqrt</span><span style="color: #008000;">&#40;</span> <span style="color: #0000dd;">1</span> <span style="color: #000040;">-</span> cosAlpha <span style="color: #000040;">*</span> cosAlpha <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> sinAlpha <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">float</span> x <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span> r <span style="color: #000040;">-</span> d <span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> sinAlpha<span style="color: #008080;">;</span>
&nbsp;
			sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> z2 <span style="color: #000080;">=</span> z <span style="color: #000040;">-</span> x <span style="color: #000040;">*</span> v0<span style="color: #008080;">;</span>
			myCircleCorrectDest.<span style="color: #007788;">SetPosition</span><span style="color: #008000;">&#40;</span> z2 <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #666666;">//Normale konnte nicht berechnet werden, </span>
		<span style="color: #666666;">//also liegen pl1 und pl2 auf einem Punkt,</span>
		<span style="color: #666666;">//also ist BoundingLine nicht vorhanden,</span>
		<span style="color: #666666;">//also ist myCircleCorrectDest = myCircleDest</span>
		myCircleCorrectDest.<span style="color: #007788;">SetPosition</span><span style="color: #008000;">&#40;</span> z <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://xaedes.de/blog/2011/02/06/bewegung-mit-kollisionserkennung-teil-3-demo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bewegung mit Kollisionserkennung Teil 3</title>
		<link>http://xaedes.de/blog/2011/02/06/bewegung-mit-kollisionserkennung-teil-3/</link>
		<comments>http://xaedes.de/blog/2011/02/06/bewegung-mit-kollisionserkennung-teil-3/#comments</comments>
		<pubDate>Sun, 06 Feb 2011 20:04:14 +0000</pubDate>
		<dc:creator><![CDATA[xaedes]]></dc:creator>
				<category><![CDATA[Kaufhausschlacht]]></category>

		<guid isPermaLink="false">http://xaedes.de/blog/?p=564</guid>
		<description><![CDATA[Teil 1 &#8211; Einführung Teil 2 &#8211; Kollision mit Gerade Teil 2 &#8211; Kollision mit Gerade &#8211; Demoprogramm Teil 3 &#8211; Kollision mit Strecke Teil 3 &#8211; Kollision mit Strecke &#8211; Demoprogramm Übersicht: Problem Lösungsansatz Die Lösung Geradenschnittpunkt Parametergleichung umgekehrt Ende und Demo Das Problem Beim Herumspielen mit dem Demoprogramm fällt schnell auf, was wir [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><a href="http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-1/">Teil 1 &#8211; Einführung</a><br />
<a href="http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-2/">Teil 2 &#8211; Kollision mit Gerade</a><br />
<a href="http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-2-demo/">Teil 2 &#8211; Kollision mit Gerade &#8211;  Demoprogramm</a><br />
<a href="http://xaedes.de/blog/2011/02/06/bewegung-mit-kollisionserkennung-teil-3/"><strong>Teil 3 &#8211; Kollision mit Strecke</strong></a><br />
<a href="http://xaedes.de/blog/2011/02/06/bewegung-mit-kollisionserkennung-teil-3-demo/">Teil 3 &#8211; Kollision mit Strecke &#8211;  Demoprogramm</a></p>
<p>Übersicht:</p>
<ol>
<li><a href="#problem">Problem</a></li>
<li><a href="#lsgansatz">Lösungsansatz</a></li>
<li><a href="#lsg">Die Lösung</a></li>
<li><a href="#LineIntersection">Geradenschnittpunkt</a></li>
<li><a href="#paramreverse">Parametergleichung umgekehrt</a></li>
<li><a href="#demo">Ende und Demo</a></li>
</ol>
<p><a name="problem"></a><br />
<h5>Das Problem</h5>
<p>Beim Herumspielen mit dem Demoprogramm fällt schnell auf, was wir noch beachten müssen. Die Kollision wird selbst dann berechnet, wenn die Bewegung gänzlich außerhalb der Begrenzungskante verläuft, wie hier veranschaulicht:<br />
<img src="http://xaedes.de/blog/wp-content/uploads/bild10.png" alt="" title="bild10" width="579" height="499" class="alignnone size-full wp-image-567" /><br />
Dabei wäre die unkorrigierte Zielposition die korrekte. Wir müssen also entscheiden, ob eine Bewegung eine Begrenzungskante berührt oder nicht.<br />
Dazu könnten wir einfach den Schnittpunkt <img src='http://s0.wp.com/latex.php?latex=S_%7Bg%2Ch%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='S_{g,h}' title='S_{g,h}' class='latex' /> der Geraden <img src='http://s0.wp.com/latex.php?latex=g&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g' title='g' class='latex' /> und <img src='http://s0.wp.com/latex.php?latex=h&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='h' title='h' class='latex' /> bestimmen und überprüfen, ob dieser innerhalb der Strecke zwischen <img src='http://s0.wp.com/latex.php?latex=p_%7BL1%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='p_{L1}' title='p_{L1}' class='latex' /> und <img src='http://s0.wp.com/latex.php?latex=p_%7BL2%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='p_{L2}' title='p_{L2}' class='latex' /> liegt. Wenn nicht, wird keine Kollisionserkennung durchgeführt. Allerdings würde dann folgendes passieren:<br />
<img src="http://xaedes.de/blog/wp-content/uploads/bild11.png" alt="" title="bild11" width="579" height="499" class="alignnone size-full wp-image-571" /><br />
Der Schnittpunkt <img src='http://s0.wp.com/latex.php?latex=S_%7Bg%2Ch%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='S_{g,h}' title='S_{g,h}' class='latex' /> liegt außerhalb der Strecke zwischen <img src='http://s0.wp.com/latex.php?latex=p_%7BL1%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='p_{L1}' title='p_{L1}' class='latex' /> und <img src='http://s0.wp.com/latex.php?latex=p_%7BL2%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='p_{L2}' title='p_{L2}' class='latex' /> und eine Kollisionserkennung würde nicht durchgeführt werden.<br />
Allerdings findet eine Kollision statt, wie der rote Kreis verdeutlicht.<br />
<a name="lsgansatz"></a><br />
<h5>Lösungsansatz</h5>
<p>Dadurch dass wir nicht nur eine Kollision für einen Punkt sondern für Kreise berechnen wollen, müssen wir auch die äußeren Begrenzungslinien der Bewegung daraufhin überprüfen, ob die Bewegung mit der Begrenzungskante kollidiert:<br />
<img src="http://xaedes.de/blog/wp-content/uploads/bild12.png" alt="" title="bild12" width="579" height="539" class="alignnone size-full wp-image-574" /><br />
Die Punkte <img src='http://s0.wp.com/latex.php?latex=A_1&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='A_1' title='A_1' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=B_1&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='B_1' title='B_1' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=A_2&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='A_2' title='A_2' class='latex' /> und <img src='http://s0.wp.com/latex.php?latex=B_2&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='B_2' title='B_2' class='latex' /> spannen ein Rechteck auf, welches die Bewegung vollständig erfasst. Jetzt muss überprüft werden ob einer der Schnittpunkte <img src='http://s0.wp.com/latex.php?latex=S_%7Bg%2Ch%2C1%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='S_{g,h,1}' title='S_{g,h,1}' class='latex' /> und <img src='http://s0.wp.com/latex.php?latex=S_%7Bg%2Ch%2C2%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='S_{g,h,2}' title='S_{g,h,2}' class='latex' /> zwischen <img src='http://s0.wp.com/latex.php?latex=p_%7BL1%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='p_{L1}' title='p_{L1}' class='latex' /> und <img src='http://s0.wp.com/latex.php?latex=p_%7BL2%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='p_{L2}' title='p_{L2}' class='latex' /> liegen. Zusätzlich kann es noch einen Schnittpunkt geben, der durch die Strecke <img src='http://s0.wp.com/latex.php?latex=B_1&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='B_1' title='B_1' class='latex' /> , <img src='http://s0.wp.com/latex.php?latex=B_2&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='B_2' title='B_2' class='latex' /> entsteht. Für diesen muss die Überprüfung auch durchgeführt werden.<br />
Sollte das einer der Schnittpunkte zwischen <img src='http://s0.wp.com/latex.php?latex=p_%7BL1%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='p_{L1}' title='p_{L1}' class='latex' /> und <img src='http://s0.wp.com/latex.php?latex=p_%7BL2%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='p_{L2}' title='p_{L2}' class='latex' /> liegen, ist eine Kollision mit der Begrenzungskante eingetreten, die erkannt und korrigiert werden muss.<br />
<a name="lsg"></a><br />
<h5>Die Lösung</h5>
<p>Zuerst müssen allerdings die Punkte <img src='http://s0.wp.com/latex.php?latex=A_1&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='A_1' title='A_1' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=B_1&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='B_1' title='B_1' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=A_2&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='A_2' title='A_2' class='latex' /> und <img src='http://s0.wp.com/latex.php?latex=B_2&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='B_2' title='B_2' class='latex' /> berechnet werden. Das ist relativ einfach:<br />
<img src='http://s0.wp.com/latex.php?latex=++%5Coverrightarrow%7Bv_0%7D+%3D+%5Cfrac%7B%5Coverrightarrow%7Bv%7D%7D%7B%7C%5Coverrightarrow%7Bv%7D%7C%7D+%5C%5C++%5Coverrightarrow%7BA_1%7D+%3D+%5Coverrightarrow%7Bs%7D+%2B+%5Coverrightarrow%7Bn_%7Bh%2C0%7D%7D+%5Ccdot+r+-+%5Coverrightarrow%7Bv_0%7D+%5Ccdot+r++%5C%5C++%5Coverrightarrow%7BA_2%7D+%3D+%5Coverrightarrow%7Bs%7D+-+%5Coverrightarrow%7Bn_%7Bh%2C0%7D%7D+%5Ccdot+r+-+%5Coverrightarrow%7Bv_0%7D+%5Ccdot+r++%5C%5C++%5Coverrightarrow%7BB_1%7D+%3D+%5Coverrightarrow%7Bz%7D+%2B+%5Coverrightarrow%7Bn_%7Bh%2C0%7D%7D+%5Ccdot+r+%2B+%5Coverrightarrow%7Bv_0%7D+%5Ccdot+r++%5C%5C++%5Coverrightarrow%7BB_2%7D+%3D+%5Coverrightarrow%7Bz%7D+-+%5Coverrightarrow%7Bn_%7Bh%2C0%7D%7D+%5Ccdot+r+%2B+%5Coverrightarrow%7Bv_0%7D+%5Ccdot+r++%5C%5C++&#038;bg=ffffff&#038;fg=000000&#038;s=2' alt='  \overrightarrow{v_0} = \frac{\overrightarrow{v}}{|\overrightarrow{v}|} \\  \overrightarrow{A_1} = \overrightarrow{s} + \overrightarrow{n_{h,0}} \cdot r - \overrightarrow{v_0} \cdot r  \\  \overrightarrow{A_2} = \overrightarrow{s} - \overrightarrow{n_{h,0}} \cdot r - \overrightarrow{v_0} \cdot r  \\  \overrightarrow{B_1} = \overrightarrow{z} + \overrightarrow{n_{h,0}} \cdot r + \overrightarrow{v_0} \cdot r  \\  \overrightarrow{B_2} = \overrightarrow{z} - \overrightarrow{n_{h,0}} \cdot r + \overrightarrow{v_0} \cdot r  \\  ' title='  \overrightarrow{v_0} = \frac{\overrightarrow{v}}{|\overrightarrow{v}|} \\  \overrightarrow{A_1} = \overrightarrow{s} + \overrightarrow{n_{h,0}} \cdot r - \overrightarrow{v_0} \cdot r  \\  \overrightarrow{A_2} = \overrightarrow{s} - \overrightarrow{n_{h,0}} \cdot r - \overrightarrow{v_0} \cdot r  \\  \overrightarrow{B_1} = \overrightarrow{z} + \overrightarrow{n_{h,0}} \cdot r + \overrightarrow{v_0} \cdot r  \\  \overrightarrow{B_2} = \overrightarrow{z} - \overrightarrow{n_{h,0}} \cdot r + \overrightarrow{v_0} \cdot r  \\  ' class='latex' /></p>
<p>Wie prüft man nun, ob zwei Strecken sich kreuzen? Erstmal sollte man überprüfen, ob sich die beiden Geraden die durch die beiden Strecken aufgespannt werden überschneiden. Sollte das der Fall sein kann man an Hand des Schnittpunktes, testen ob dieser innerhalb der beiden Strecken liegt.<br />
Alle Punkte <img src='http://s0.wp.com/latex.php?latex=x&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x' title='x' class='latex' /> auf einer Strecke zwischen <img src='http://s0.wp.com/latex.php?latex=s&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='s' title='s' class='latex' /> und <img src='http://s0.wp.com/latex.php?latex=e&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='e' title='e' class='latex' /> sind durch die Parametergleichung<br />
<img src='http://s0.wp.com/latex.php?latex=++%5Coverrightarrow%7Bx%7D+%3D+%5Coverrightarrow%7Bs%7D+%2B+k+%5Ccdot+%28+%5Coverrightarrow%7Be%7D+-+%5Coverrightarrow%7Bs%7D+%29+%5C%5C++0+%5Cle+k+%5Cle+1++&#038;bg=ffffff&#038;fg=000000&#038;s=2' alt='  \overrightarrow{x} = \overrightarrow{s} + k \cdot ( \overrightarrow{e} - \overrightarrow{s} ) \\  0 \le k \le 1  ' title='  \overrightarrow{x} = \overrightarrow{s} + k \cdot ( \overrightarrow{e} - \overrightarrow{s} ) \\  0 \le k \le 1  ' class='latex' /><br />
bestimmt.<br />
Haben wir den Schnittpunkt der beiden Geraden also erst einmal gefunden, müssen wir für diesen Punkt <img src='http://s0.wp.com/latex.php?latex=x&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x' title='x' class='latex' /> nur noch den Parameter <img src='http://s0.wp.com/latex.php?latex=k&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='k' title='k' class='latex' /> für beide Strecken bestimmen. Liegen beide Parameter innerhalb des Intervals <img src='http://s0.wp.com/latex.php?latex=%5B0..1%5D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='[0..1]' title='[0..1]' class='latex' />, so kreuzen sich die Strecken:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">bool</span> TestBoundedMovement<span style="color: #008080;">::</span><span style="color: #007788;">DoLineSegmentsIntersect</span><span style="color: #008000;">&#40;</span> sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> s1, sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> e1, 
	sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> s2, sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> e2 <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> v1 <span style="color: #000080;">=</span> e1 <span style="color: #000040;">-</span> s1<span style="color: #008080;">;</span>
	sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> v2 <span style="color: #000080;">=</span> e2 <span style="color: #000040;">-</span> s2<span style="color: #008080;">;</span>
	sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> intersection<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> LinesIntersection<span style="color: #008000;">&#40;</span> s1, v1, s2, v2, intersection <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">float</span> k <span style="color: #000080;">=</span> LineParam<span style="color: #008000;">&#40;</span> s1, v1, intersection <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">float</span> m <span style="color: #000080;">=</span> LineParam<span style="color: #008000;">&#40;</span> s2, v2, intersection <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#40;</span> m <span style="color: #000080;">&gt;=</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span> m <span style="color: #000080;">&lt;=</span> <span style="color: #0000dd;">1</span> <span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;&amp;</span>
			<span style="color: #008000;">&#40;</span> k <span style="color: #000080;">&gt;=</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span> k <span style="color: #000080;">&lt;=</span> <span style="color: #0000dd;">1</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>  <span style="color: #0000ff;">else</span> 
		<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p><a name="LineIntersection"></a><br />
<h5>Geradenschnittpunkt</h5>
<p>Die mathematischen Hintergründe für die Berechnung eines Geradenschnittpunktes sind hier zu finden : <a href="http://xaedes.de/blog/2011/02/06/schnittpunkt-zweier-geraden/">Schnittpunkt zweier Geraden</a></p>
<p>Daraus ergibt sich folgender Programmcode:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">bool</span> TestBoundedMovement<span style="color: #008080;">::</span><span style="color: #007788;">LinesIntersection</span><span style="color: #008000;">&#40;</span> sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> s1, sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> v1, 
	sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> s2, sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> v2, sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> <span style="color: #000040;">&amp;</span>intersection <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> v1.<span style="color: #007788;">x</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">float</span> a <span style="color: #000080;">=</span> v2.<span style="color: #007788;">x</span> <span style="color: #000040;">*</span> v1.<span style="color: #007788;">y</span> <span style="color: #000040;">/</span> v1.<span style="color: #007788;">x</span> <span style="color: #000040;">-</span> v2.<span style="color: #007788;">y</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> a <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">float</span> m <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span> s2.<span style="color: #007788;">y</span> <span style="color: #000040;">-</span> s1.<span style="color: #007788;">y</span> <span style="color: #000040;">-</span> <span style="color: #008000;">&#40;</span> s2.<span style="color: #007788;">x</span> <span style="color: #000040;">-</span> s1.<span style="color: #007788;">x</span> <span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span> v1.<span style="color: #007788;">y</span> <span style="color: #000040;">/</span> v1.<span style="color: #007788;">x</span> <span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> a<span style="color: #008080;">;</span>
			intersection.<span style="color: #007788;">x</span> <span style="color: #000080;">=</span> s2.<span style="color: #007788;">x</span> <span style="color: #000040;">+</span> m <span style="color: #000040;">*</span> v2.<span style="color: #007788;">x</span><span style="color: #008080;">;</span>
			intersection.<span style="color: #007788;">y</span> <span style="color: #000080;">=</span> s2.<span style="color: #007788;">y</span> <span style="color: #000040;">+</span> m <span style="color: #000040;">*</span> v2.<span style="color: #007788;">y</span><span style="color: #008080;">;</span>
			<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> v2.<span style="color: #007788;">x</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">float</span> m <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span> s1.<span style="color: #007788;">x</span> <span style="color: #000040;">-</span> s2.<span style="color: #007788;">x</span> <span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> v2.<span style="color: #007788;">x</span><span style="color: #008080;">;</span>
			intersection.<span style="color: #007788;">x</span> <span style="color: #000080;">=</span> s2.<span style="color: #007788;">x</span> <span style="color: #000040;">+</span> m <span style="color: #000040;">*</span> v2.<span style="color: #007788;">x</span><span style="color: #008080;">;</span>
			intersection.<span style="color: #007788;">y</span> <span style="color: #000080;">=</span> s2.<span style="color: #007788;">y</span> <span style="color: #000040;">+</span> m <span style="color: #000040;">*</span> v2.<span style="color: #007788;">y</span><span style="color: #008080;">;</span>
			<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p><a name="paramreverse"></a><br />
<h5>Parametergleichung umgekehrt</h5>
<p>Möchte man den Parameter aus der Parametergleichung eines Punktes auf einer Geraden berechnen, muss man diese nur umstellen. Auf Grund der Trivialität dieses Vorgangs lasse ich die mathematischen Hintergründe hier ganz außen vor. Folgender Quellcode ergibt sich:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">float</span> TestBoundedMovement<span style="color: #008080;">::</span><span style="color: #007788;">LineParam</span><span style="color: #008000;">&#40;</span> sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> s, sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> v, sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> p <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">float</span> k <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> v.<span style="color: #007788;">y</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		k <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>p.<span style="color: #007788;">y</span> <span style="color: #000040;">-</span> s.<span style="color: #007788;">y</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> v.<span style="color: #007788;">y</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> v.<span style="color: #007788;">x</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		k <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>p.<span style="color: #007788;">x</span> <span style="color: #000040;">-</span> s.<span style="color: #007788;">x</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> v.<span style="color: #007788;">x</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">return</span> k <span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p><a name="demo"></a><br />
<h5>Ende und Demo</h5>
<p>Nun muss nur noch die Überprüfung für die beiden Strecken eingebaut werden:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">//...</span>
<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> <span style="color: #000040;">!</span> DoLineSegmentsIntersect<span style="color: #008000;">&#40;</span> s <span style="color: #000040;">+</span> nh0 <span style="color: #000040;">*</span> r, z <span style="color: #000040;">+</span> v0 <span style="color: #000040;">*</span> r <span style="color: #000040;">+</span> nh0 <span style="color: #000040;">*</span> r, pl1, pl2 <span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;&amp;</span>
    <span style="color: #000040;">!</span> DoLineSegmentsIntersect<span style="color: #008000;">&#40;</span> s <span style="color: #000040;">-</span> nh0 <span style="color: #000040;">*</span> r, z <span style="color: #000040;">+</span> v0 <span style="color: #000040;">*</span> r <span style="color: #000040;">-</span> nh0 <span style="color: #000040;">*</span> r, pl1, pl2 <span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;&amp;</span>
    <span style="color: #000040;">!</span> DoLineSegmentsIntersect<span style="color: #008000;">&#40;</span> z <span style="color: #000040;">+</span> v0 <span style="color: #000040;">*</span> r <span style="color: #000040;">+</span> nh0 <span style="color: #000040;">*</span> r, z <span style="color: #000040;">+</span> v0 <span style="color: #000040;">*</span> r <span style="color: #000040;">-</span> nh0 <span style="color: #000040;">*</span> r, pl1, pl2 <span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #666666;">//Bewegungslinie und BoundLine überschneiden sich nicht,</span>
	<span style="color: #666666;">//also wird keine Kollisionserkennung vorgenommen,</span>
	<span style="color: #666666;">//also ist myCircleCorrectDest = myCircleDest</span>
	myCircleCorrectDest.<span style="color: #007788;">SetPosition</span><span style="color: #008000;">&#40;</span> z <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">return</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #666666;">//...</span></pre></td></tr></table></div>

<p>Dazu gibt es wieder ein Demonstrationsprogramm:<br />
<a href="http://xaedes.de/blog/2011/02/06/bewegung-mit-kollisionserkennung-teil-3-demo/">Demonstrationsprogramm zu diesem Teil</a></p>
]]></content:encoded>
			<wfw:commentRss>http://xaedes.de/blog/2011/02/06/bewegung-mit-kollisionserkennung-teil-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bewegung mit Kollisionserkennung Teil 2 &#8211; Demonstrationsprogramm</title>
		<link>http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-2-demo/</link>
		<comments>http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-2-demo/#comments</comments>
		<pubDate>Fri, 04 Feb 2011 14:46:47 +0000</pubDate>
		<dc:creator><![CDATA[xaedes]]></dc:creator>
				<category><![CDATA[Kaufhausschlacht]]></category>

		<guid isPermaLink="false">http://xaedes.de/blog/?p=534</guid>
		<description><![CDATA[Teil 1 &#8211; Einführung Teil 2 &#8211; Kollision mit Gerade Teil 2 &#8211; Kollision mit Gerade &#8211; Demoprogramm Teil 3 &#8211; Kollision mit Strecke Teil 3 &#8211; Kollision mit Strecke &#8211; Demoprogramm Zur Demonstration der bisherigen Lösung habe ich ein kleines Programm geschrieben, in welchem man sich die berechnete Lösung für beliebe Ausgangssituationen anzeigen lassen [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><a href="http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-1/">Teil 1 &#8211; Einführung</a><br />
<a href="http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-2/">Teil 2 &#8211; Kollision mit Gerade</a><br />
<a href="http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-2-demo/"><strong>Teil 2 &#8211; Kollision mit Gerade &#8211;  Demoprogramm</strong></a><br />
<a href="http://xaedes.de/blog/2011/02/06/bewegung-mit-kollisionserkennung-teil-3/">Teil 3 &#8211; Kollision mit Strecke</a><br />
<a href="http://xaedes.de/blog/2011/02/06/bewegung-mit-kollisionserkennung-teil-3-demo/">Teil 3 &#8211; Kollision mit Strecke &#8211;  Demoprogramm</a></p>
<p>Zur Demonstration der bisherigen Lösung habe ich ein kleines Programm geschrieben, in welchem man sich die berechnete Lösung für beliebe Ausgangssituationen anzeigen lassen kann. Es zeigt intuitiv die Probleme, die bisher noch nicht gelöst wurden.<br />
Screenshot:<br />
<img src="http://xaedes.de/blog/wp-content/uploads/Bildschirmfoto3-300x218.png" alt="" title="Bildschirmfoto3" width="300" height="218" class="alignnone size-medium wp-image-535" /></p>
<p>Bedienung :<br />
Linke Maustaste, Drag&#038;Drop : roter und schwarzer Kreis, Enden der schwarzen Linie<br />
Rechte Maustaste, Drag&#038;Drop : Bildschirmausschnitt<br />
Mausrad : Zoomen</p>
<p>Ausprobieren : <a href='http://xaedes.de/blog/wp-content/uploads/win-04.02.2011-21.26.zip'>win-04.02.2011-21.26</a></p>
<p>Relevanter Quellcodeausschnitt:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">void</span> TestBoundedMovement<span style="color: #008080;">::</span><span style="color: #007788;">UpdateCorrectDest</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> s <span style="color: #000080;">=</span> myCircleStart.<span style="color: #007788;">GetPosition</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> v <span style="color: #000080;">=</span> myVector<span style="color: #008080;">;</span>
	sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> pl1 <span style="color: #000080;">=</span> myLineBound.<span style="color: #007788;">GetP1</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> pl2 <span style="color: #000080;">=</span> myLineBound.<span style="color: #007788;">GetP2</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> z <span style="color: #000080;">=</span> s <span style="color: #000040;">+</span> v<span style="color: #008080;">;</span>
&nbsp;
	sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> ng0<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> MathUtils<span style="color: #008080;">::</span><span style="color: #007788;">ComputeNormal</span><span style="color: #008000;">&#40;</span> pl1, pl2, ng0 <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
&nbsp;
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> MathUtils<span style="color: #008080;">::</span><span style="color: #007788;">DotProduct</span><span style="color: #008000;">&#40;</span> v, ng0 <span style="color: #008000;">&#41;</span> <span style="color: #000080;">&gt;</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #666666;">//Bewegungsvektor zeigt von BoundingLine weg,</span>
			<span style="color: #666666;">//also wird keine Kollisionserkennung vorgenommen,</span>
			<span style="color: #666666;">//also ist myCircleCorrectDest = myCircleDest</span>
			myCircleCorrectDest.<span style="color: #007788;">SetPosition</span><span style="color: #008000;">&#40;</span> z <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			<span style="color: #0000ff;">return</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> MathUtils<span style="color: #008080;">::</span><span style="color: #007788;">DotProduct</span><span style="color: #008000;">&#40;</span> s <span style="color: #000040;">-</span> pl2, ng0 <span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #666666;">//Der Startpunkt liegt hinter der Line</span>
			<span style="color: #666666;">//also wird keine Kollisionserkennung vorgenommen,</span>
			<span style="color: #666666;">//also ist myCircleCorrectDest = myCircleDest</span>
			myCircleCorrectDest.<span style="color: #007788;">SetPosition</span><span style="color: #008000;">&#40;</span> z <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			<span style="color: #0000ff;">return</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
&nbsp;
		<span style="color: #0000ff;">float</span> r <span style="color: #000080;">=</span> radius<span style="color: #008080;">;</span>
		<span style="color: #0000ff;">float</span> d <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span> MathUtils<span style="color: #008080;">::</span><span style="color: #007788;">DotProduct</span><span style="color: #008000;">&#40;</span> z <span style="color: #000040;">-</span> pl2, ng0 <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> d <span style="color: #000080;">&gt;=</span> r <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #666666;">//Es findet gar keine Kollision statt</span>
			<span style="color: #666666;">//also ist myCircleCorrectDest = myCircleDest</span>
			myCircleCorrectDest.<span style="color: #007788;">SetPosition</span><span style="color: #008000;">&#40;</span> z <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			<span style="color: #0000ff;">return</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #0000ff;">float</span> cosAlpha <span style="color: #000080;">=</span> MathUtils<span style="color: #008080;">::</span><span style="color: #007788;">DotProduct</span><span style="color: #008000;">&#40;</span> v, pl2 <span style="color: #000040;">-</span> pl1 <span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> 
				<span style="color: #008000;">&#40;</span> MathUtils<span style="color: #008080;">::</span><span style="color: #007788;">VectorLen</span><span style="color: #008000;">&#40;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span>  
				  MathUtils<span style="color: #008080;">::</span><span style="color: #007788;">VectorLen</span><span style="color: #008000;">&#40;</span> pl2 <span style="color: #000040;">-</span> pl1 <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
&nbsp;
		<span style="color: #0000ff;">float</span> sinAlpha <span style="color: #000080;">=</span> <span style="color: #0000dd;">sqrt</span><span style="color: #008000;">&#40;</span> <span style="color: #0000dd;">1</span> <span style="color: #000040;">-</span> cosAlpha <span style="color: #000040;">*</span> cosAlpha <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> sinAlpha <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">float</span> x <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span> r <span style="color: #000040;">-</span> d <span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> sinAlpha<span style="color: #008080;">;</span>
&nbsp;
			sf<span style="color: #008080;">::</span><span style="color: #007788;">Vector2f</span> z2 <span style="color: #000080;">=</span> z <span style="color: #000040;">-</span> x <span style="color: #000040;">*</span> v <span style="color: #000040;">/</span> MathUtils<span style="color: #008080;">::</span><span style="color: #007788;">VectorLen</span><span style="color: #008000;">&#40;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			myCircleCorrectDest.<span style="color: #007788;">SetPosition</span><span style="color: #008000;">&#40;</span> z2 <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #666666;">//Normale konnte nicht berechnet werden, </span>
		<span style="color: #666666;">//also liegen pl1 und pl2 auf einem Punkt,</span>
		<span style="color: #666666;">//also ist BoundingLine nicht vorhanden,</span>
		<span style="color: #666666;">//also ist myCircleCorrectDest = myCircleDest</span>
		myCircleCorrectDest.<span style="color: #007788;">SetPosition</span><span style="color: #008000;">&#40;</span> z <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-2-demo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bewegung mit Kollisionserkennung Teil 2</title>
		<link>http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-2/</link>
		<comments>http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-2/#comments</comments>
		<pubDate>Fri, 04 Feb 2011 12:52:47 +0000</pubDate>
		<dc:creator><![CDATA[xaedes]]></dc:creator>
				<category><![CDATA[Kaufhausschlacht]]></category>

		<guid isPermaLink="false">http://xaedes.de/blog/?p=470</guid>
		<description><![CDATA[Teil 1 &#8211; Einführung Teil 2 &#8211; Kollision mit Gerade Teil 2 &#8211; Kollision mit Gerade &#8211; Demoprogramm Teil 3 &#8211; Kollision mit Strecke Teil 3 &#8211; Kollision mit Strecke &#8211; Demoprogramm Übersicht: Rechenweg Quellcode und Demo So jetzt wissen wir was wir brauchen. Damit fangen die Berechnungen auch schon an. Zusätzlich brauchen wir aber [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><a href="http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-1/">Teil 1 &#8211; Einführung</a><br />
<a href="http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-2/"><strong>Teil 2 &#8211; Kollision mit Gerade</strong></a><br />
<a href="http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-2-demo/">Teil 2 &#8211; Kollision mit Gerade &#8211;  Demoprogramm</a><br />
<a href="http://xaedes.de/blog/2011/02/06/bewegung-mit-kollisionserkennung-teil-3/">Teil 3 &#8211; Kollision mit Strecke</a><br />
<a href="http://xaedes.de/blog/2011/02/06/bewegung-mit-kollisionserkennung-teil-3-demo/">Teil 3 &#8211; Kollision mit Strecke &#8211;  Demoprogramm</a></p>
<p>Übersicht:</p>
<ol>
<li><a href="#rechenweg">Rechenweg</a></li>
<li><a href="#demo">Quellcode und Demo</a></li>
</ol>
<p>So jetzt wissen wir was wir brauchen. Damit fangen die Berechnungen auch schon an. Zusätzlich brauchen wir aber noch den Lot von der Begrenzungslinie zu den beiden Zielpunkten <img src='http://s0.wp.com/latex.php?latex=z&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='z' title='z' class='latex' /> und <img src='http://s0.wp.com/latex.php?latex=z%26%238216%3B&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='z&#8216;' title='z&#8216;' class='latex' />. Der Lot zu <img src='http://s0.wp.com/latex.php?latex=z%26%238216%3B&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='z&#8216;' title='z&#8216;' class='latex' /> sollte eine Länge von <img src='http://s0.wp.com/latex.php?latex=r&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='r' title='r' class='latex' />, also dem Radius des Figurenkreises haben, damit die Figur die Begrenzungslinie gerade so nicht überschreitet. Die Länge des Lotes zu <img src='http://s0.wp.com/latex.php?latex=z&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='z' title='z' class='latex' /> bezeichnen wir mit <img src='http://s0.wp.com/latex.php?latex=d&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='d' title='d' class='latex' />.<br />
<img src="http://xaedes.de/blog/wp-content/uploads/bild5.png" alt="" title="bild5" width="579" height="419" class="alignnone size-full wp-image-438" /></p>
<p>Das führt uns zu folgender Skizze des zu Grunde liegenden mathematischen Problemes:<br />
<img src="http://xaedes.de/blog/wp-content/uploads/bild6.png" alt="" title="bild6" width="579" height="319" class="alignnone size-full wp-image-495" /><br />
Die gepunktete Seite unter der Geraden <img src='http://s0.wp.com/latex.php?latex=g&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g' title='g' class='latex' /> ist der abzugrenzende Bereich.</p>
<p>Nochmal eine Zusammenfassung aller Variablen:</p>
<table>
<tr>
<td><img src='http://s0.wp.com/latex.php?latex=s&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='s' title='s' class='latex' /></td>
<td> Startpunkt </td>
</tr>
<tr>
<td><img src='http://s0.wp.com/latex.php?latex=v&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='v' title='v' class='latex' /></td>
<td> Bewegungsvektor </td>
</tr>
<tr>
<td><img src='http://s0.wp.com/latex.php?latex=z&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='z' title='z' class='latex' /></td>
<td> unkorrigierter Zielpunkt</td>
</tr>
<tr>
<td><img src='http://s0.wp.com/latex.php?latex=z%26%238216%3B&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='z&#8216;' title='z&#8216;' class='latex' /></td>
<td> korrigierter Zielpunkt </td>
</tr>
<tr>
<td><img src='http://s0.wp.com/latex.php?latex=r&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='r' title='r' class='latex' /></td>
<td> Radius der Figur </td>
</tr>
<tr>
<td><img src='http://s0.wp.com/latex.php?latex=d&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='d' title='d' class='latex' /></td>
<td> Abstand des unkorrigierten Zielpunktes zur Begrenzungskante </td>
</tr>
<tr>
<td><img src='http://s0.wp.com/latex.php?latex=x&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x' title='x' class='latex' /></td>
<td> Abstand des unkorrigierten Zielpunktes zum korrigierten Zielpunkt</td>
</tr>
<tr>
<td><img src='http://s0.wp.com/latex.php?latex=g&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g' title='g' class='latex' /></td>
<td> Gerade, die von <img src='http://s0.wp.com/latex.php?latex=p_%7BL1%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='p_{L1}' title='p_{L1}' class='latex' /> und <img src='http://s0.wp.com/latex.php?latex=p_%7BL2%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='p_{L2}' title='p_{L2}' class='latex' /> aufgespannt wird </td>
</tr>
<tr>
<td><img src='http://s0.wp.com/latex.php?latex=h&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='h' title='h' class='latex' /></td>
<td> Gerade, die von <img src='http://s0.wp.com/latex.php?latex=s&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='s' title='s' class='latex' /> und <img src='http://s0.wp.com/latex.php?latex=v&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='v' title='v' class='latex' /> aufgespannt wird </td>
</tr>
<tr>
<td><img src='http://s0.wp.com/latex.php?latex=%5Calpha&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\alpha' title='\alpha' class='latex' /></td>
<td> Winkel zwischen den Geraden <img src='http://s0.wp.com/latex.php?latex=g&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g' title='g' class='latex' /> und <img src='http://s0.wp.com/latex.php?latex=h&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='h' title='h' class='latex' /> </td>
</tr>
<tr>
<td><img src='http://s0.wp.com/latex.php?latex=n_%7Bg%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n_{g}' title='n_{g}' class='latex' /></td>
<td> Normale zur Geraden <img src='http://s0.wp.com/latex.php?latex=g&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g' title='g' class='latex' /> </td>
</tr>
<tr>
<td><img src='http://s0.wp.com/latex.php?latex=n_%7Bh%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n_{h}' title='n_{h}' class='latex' /></td>
<td> Normale zur Geraden <img src='http://s0.wp.com/latex.php?latex=h&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='h' title='h' class='latex' /> </td>
</tr>
<tr>
<td><img src='http://s0.wp.com/latex.php?latex=p_1&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='p_1' title='p_1' class='latex' /></td>
<td> Schnittpunkt des Lotes mit dem korrigierten Zielpunkt </td>
</tr>
<tr>
<td><img src='http://s0.wp.com/latex.php?latex=p_2&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='p_2' title='p_2' class='latex' /></td>
<td> Schnittpunkt des Lotes mit dem unkorrigierten Zielpunkt </td>
</tr>
<tr>
<td><img src='http://s0.wp.com/latex.php?latex=p_%7BL1%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='p_{L1}' title='p_{L1}' class='latex' /></td>
<td> Erster Endpunkt der Begrenzungskante </td>
</tr>
<tr>
<td><img src='http://s0.wp.com/latex.php?latex=p_%7BL2%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='p_{L2}' title='p_{L2}' class='latex' /></td>
<td> Zweiter Endpunkt der Begrenzungskante </td>
</tr>
</table>
<p></p>
<p><strong><span id="more-470"></span>Wichtig</strong> ist dabei noch zu erwähnen, dass die Endpunkte der Begrenzungskanten einer BoundingBox gegen den Uhrzeigersinn angegeben werden müssen. Damit können wir an Hand der Normale der Begrenzungskante bestimmen, ob ein Punkt außerhalb der BoundingBox oder innerhalb liegt. Wenn die Punkte richtig angegeben sind zeigt die Normale nach außen wie in der Skizze zu sehen ist.</p>
<h6>Achtung Fehlerquelle !!!</h6>
<p>In der Computergrafik ist das Koordinatensystem normalerweise kopfüber gezeichnet, so dass die linke obere Ecke des Zeichenbereichs den Koordinatenursprung bildet und die Achsen nach rechts und nach unten verlaufen. Auf Grund dessen <strong>ändert sich hier die Reihenfolge</strong> in der die Kanten angegeben werden müssen. Bei seltsamen Ergebnissen, sollte man überprüfen, ob man hierauf geachtet hat.</p>
<p><a name="rechenweg"></a><br />
<h5>Nun zum Rechenweg</h5>
<img src='http://s0.wp.com/latex.php?latex=gegeben%3A+%5C%5C++s%2C+%5Coverrightarrow%7Bv%7D%2C+p_%7BL1%7D%2C+p_%7BL2%7D%5C%5C++gesucht%3A+%5C%5C++z%27%5C%5C++&#038;bg=ffffff&#038;fg=000000&#038;s=3' alt='gegeben: \\  s, \overrightarrow{v}, p_{L1}, p_{L2}\\  gesucht: \\  z&#039;\\  ' title='gegeben: \\  s, \overrightarrow{v}, p_{L1}, p_{L2}\\  gesucht: \\  z&#039;\\  ' class='latex' />
<p>Der korrigierten Zielpunkt <img src='http://s0.wp.com/latex.php?latex=z%26%238216%3B&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='z&#8216;' title='z&#8216;' class='latex' /> kann berechnet werden indem vom unkorrigierten Zielpunkt <img src='http://s0.wp.com/latex.php?latex=z&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='z' title='z' class='latex' /> der auf Länge <img src='http://s0.wp.com/latex.php?latex=x&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x' title='x' class='latex' /> skalierte Bewegungsvektor <img src='http://s0.wp.com/latex.php?latex=%5Coverrightarrow%7Bv%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\overrightarrow{v}' title='\overrightarrow{v}' class='latex' /> abgezogen wird:<br />
<img src='http://s0.wp.com/latex.php?latex=++z%27%3Dz-%5Cfrac%7Bx%5Ccdot+%5Coverrightarrow%7Bv%7D%7D%7B%7C%5Coverrightarrow%7Bv%7D%7C%7D+%5C%5C++&#038;bg=ffffff&#038;fg=000000&#038;s=3' alt='  z&#039;=z-\frac{x\cdot \overrightarrow{v}}{|\overrightarrow{v}|} \\  ' title='  z&#039;=z-\frac{x\cdot \overrightarrow{v}}{|\overrightarrow{v}|} \\  ' class='latex' /></p>
<p>Offensichtlich wird also der Wert von <img src='http://s0.wp.com/latex.php?latex=x&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x' title='x' class='latex' /> benötigt. Anhand der Skizze ist zu erkennen, das <img src='http://s0.wp.com/latex.php?latex=x&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x' title='x' class='latex' /> die Hypotenuse des durch <img src='http://s0.wp.com/latex.php?latex=z&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='z' title='z' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=z%26%238216%3B&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='z&#8216;' title='z&#8216;' class='latex' /> und <img src='http://s0.wp.com/latex.php?latex=%5Calpha&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\alpha' title='\alpha' class='latex' /> aufgespannten rechtwinkligen Rechteckes ist. Es gilt also folgende Beziehung:<br />
<img src='http://s0.wp.com/latex.php?latex=++r-d+%3D+sin%28%5Calpha%29%5Ccdot+x+%5C%5C++x%3D+%5Cfrac%7Br-d%7D%7Bsin%28%5Calpha%29%7D+%5C%5C++&#038;bg=ffffff&#038;fg=000000&#038;s=3' alt='  r-d = sin(\alpha)\cdot x \\  x= \frac{r-d}{sin(\alpha)} \\  ' title='  r-d = sin(\alpha)\cdot x \\  x= \frac{r-d}{sin(\alpha)} \\  ' class='latex' /></p>
<p>Der Sinus von <img src='http://s0.wp.com/latex.php?latex=%5Calpha&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\alpha' title='\alpha' class='latex' /> kann über den Kosinus von <img src='http://s0.wp.com/latex.php?latex=%5Calpha&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\alpha' title='\alpha' class='latex' /> berechnet werden, welcher über das Skalarprodukt zweier Vektoren, die die Richtung der beiden Geraden <img src='http://s0.wp.com/latex.php?latex=g&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g' title='g' class='latex' /> und <img src='http://s0.wp.com/latex.php?latex=h&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='h' title='h' class='latex' /> darstellen, berechnet wird:<br />
<img src='http://s0.wp.com/latex.php?latex=++sin%28%5Calpha%29%3D%5Csqrt%7B1-cos%5E2%28%5Calpha%29%7D+%5C%5C++%5C%5C+cos%28%5Calpha%29%3D%5Cfrac%7B%5Coverrightarrow%7Bv%7D+%5Ccdot+%28%5Coverrightarrow%7Bp_%7BL2%7D%7D-%5Coverrightarrow%7Bp_%7BL1%7D%7D%29%7D++%7B%7C%5Coverrightarrow%7Bv%7D%7C+%5Ccdot+%7C+%5Coverrightarrow%7Bp_%7BL2%7D%7D-%5Coverrightarrow%7Bp_%7BL1%7D%7D+%7C%7D+%5C%5C+%5C%5C+%5C%5C++&#038;bg=ffffff&#038;fg=000000&#038;s=3' alt='  sin(\alpha)=\sqrt{1-cos^2(\alpha)} \\  \\ cos(\alpha)=\frac{\overrightarrow{v} \cdot (\overrightarrow{p_{L2}}-\overrightarrow{p_{L1}})}  {|\overrightarrow{v}| \cdot | \overrightarrow{p_{L2}}-\overrightarrow{p_{L1}} |} \\ \\ \\  ' title='  sin(\alpha)=\sqrt{1-cos^2(\alpha)} \\  \\ cos(\alpha)=\frac{\overrightarrow{v} \cdot (\overrightarrow{p_{L2}}-\overrightarrow{p_{L1}})}  {|\overrightarrow{v}| \cdot | \overrightarrow{p_{L2}}-\overrightarrow{p_{L1}} |} \\ \\ \\  ' class='latex' /></p>
<p>Weiterhin muss noch der Abstand <img src='http://s0.wp.com/latex.php?latex=d&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='d' title='d' class='latex' /> des unkorrigierten Zielpunktes <img src='http://s0.wp.com/latex.php?latex=z&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='z' title='z' class='latex' /> zur Geraden <img src='http://s0.wp.com/latex.php?latex=g&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g' title='g' class='latex' /> berechnet werden. </p>
<p><img src='http://s0.wp.com/latex.php?latex=++d%3D%28%5Coverrightarrow%7Bz%7D-%5Coverrightarrow%7Bp_%7BL2%7D%7D%29+%5Ccdot+%5Coverrightarrow%7Bn_%7Bg%2C0%7D%7D++%5C%5C++&#038;bg=ffffff&#038;fg=000000&#038;s=3' alt='  d=(\overrightarrow{z}-\overrightarrow{p_{L2}}) \cdot \overrightarrow{n_{g,0}}  \\  ' title='  d=(\overrightarrow{z}-\overrightarrow{p_{L2}}) \cdot \overrightarrow{n_{g,0}}  \\  ' class='latex' /><br />
Eigentlich ist das nicht wirklich der Abstand, da nicht der Betrag, sondern ein vorzeichenbehafteter Wert übernommen wird. Hier ist die Orientierung der Normale der Geraden <img src='http://s0.wp.com/latex.php?latex=g&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='g' title='g' class='latex' /> wichtig. Sollte <img src='http://s0.wp.com/latex.php?latex=z&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='z' title='z' class='latex' /> außerhalb des von der Begrenzungskante begrenzten Bereiches liegen, ist dieser Wert positiv, sollte er innerhalb liegen, ist er negativ. Sollte dies der Fall sein ergibt sich folgende Situation:<br />
<img src="http://xaedes.de/blog/wp-content/uploads/bild7.png" alt="" title="bild7" width="579" height="319" class="alignnone size-full wp-image-545" /></p>
<p>Da <img src='http://s0.wp.com/latex.php?latex=d&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='d' title='d' class='latex' /> negativ ist, gilt weiterhin folgende Beziehung:<br />
<img src='http://s0.wp.com/latex.php?latex=++x%3D+%5Cfrac%7Br-d%7D%7Bsin%28%5Calpha%29%7D+%5C%5C+%5C%5C+%5C%5C++x%3D+%5Cfrac%7Br%2B%7Cd%7C%7D%7Bsin%28%5Calpha%29%7D+%5C%5C++&#038;bg=ffffff&#038;fg=000000&#038;s=3' alt='  x= \frac{r-d}{sin(\alpha)} \\ \\ \\  x= \frac{r+|d|}{sin(\alpha)} \\  ' title='  x= \frac{r-d}{sin(\alpha)} \\ \\ \\  x= \frac{r+|d|}{sin(\alpha)} \\  ' class='latex' /></p>
<p>Die Normale einer Gerade in der Ebene (also in 2D) wird einfach durch den Richtungsvektor der Gerade berechnet:<br />
<img src='http://s0.wp.com/latex.php?latex=++%5Coverrightarrow%7Bn_%7Bg%2C0%7D%7D+%3D+%5Cfrac%7Bn_%7Bg%7D%7D%7B%7Cn_%7Bg%7D%7C%7D+%5C%5C++%5Coverrightarrow%7Bn_%7Bg%7D%7D+%3D+++%5Cbegin%7Bpmatrix%7Dp_%7BL1%7D.y+-+p_%7BL2%7D.y++%5C%5C+p_%7BL2%7D.x+-+p_%7BL1%7D.x++%5Cend%7Bpmatrix%7D+%5C%5C++&#038;bg=ffffff&#038;fg=000000&#038;s=3' alt='  \overrightarrow{n_{g,0}} = \frac{n_{g}}{|n_{g}|} \\  \overrightarrow{n_{g}} =   \begin{pmatrix}p_{L1}.y - p_{L2}.y  \\ p_{L2}.x - p_{L1}.x  \end{pmatrix} \\  ' title='  \overrightarrow{n_{g,0}} = \frac{n_{g}}{|n_{g}|} \\  \overrightarrow{n_{g}} =   \begin{pmatrix}p_{L1}.y - p_{L2}.y  \\ p_{L2}.x - p_{L1}.x  \end{pmatrix} \\  ' class='latex' /></p>
<p>Damit lassen sich alle benötigten Werte auf bekannte Werte zurückführen und die korrigierte Zielposition <img src='http://s0.wp.com/latex.php?latex=z%26%238216%3B&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='z&#8216;' title='z&#8216;' class='latex' /> kann ausgerechnet werden.</p>
<p>Da die Begrenzungskante nicht alleine ist, sondern zusammen mit anderen Kanten einen Bereich abgrenzt, wollen wir nur die Kollision von einer Seite der Kante aus betrachten. Es könnte sonst zu ungewollten Ergebnissen kommen wie hier dargestellt:<br />
<img src="http://xaedes.de/blog/wp-content/uploads/bild9.png" alt="" title="bild9" width="579" height="479" class="alignnone size-full wp-image-550" /><br />
Wenn die rote Linie zuletzt verarbeitet würde, würde die &#8222;korrigierte&#8220; Zielposition <img src='http://s0.wp.com/latex.php?latex=z%26%238216%3B&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='z&#8216;' title='z&#8216;' class='latex' /> immer noch falsch sein. Wirklich korrekte Positionen werden wie hier durch den grünen Kreis <img src='http://s0.wp.com/latex.php?latex=z%60%60&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='z``' title='z``' class='latex' /> nur durch Kollisionen mit Linien aus der richtigen Richtung (in den abgrenzenden Bereich hinein) erzeugt.<br />
Es muss also überprüft werden, ob die Bewegung auf die Kante zu geht oder von ihr weg. Dazu folgende Skizze:<br />
<img src="http://xaedes.de/blog/wp-content/uploads/bild8.png" alt="" title="bild8" width="579" height="329" class="alignnone size-full wp-image-549" /><br />
Die blaue Gerade <img src='http://s0.wp.com/latex.php?latex=h%26%238216%3B&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='h&#8216;' title='h&#8216;' class='latex' /> führt in den abgegrenzten Bereich hinein und die rote Gerade von ihm weg.<br />
Um herauszufinden welcher Fall für die aktuelle Gerade <img src='http://s0.wp.com/latex.php?latex=h&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='h' title='h' class='latex' /> eingetreten ist, berechnen wir den vorzeichenbehafteten Abstand <img src='http://s0.wp.com/latex.php?latex=d_h&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='d_h' title='d_h' class='latex' /> und überprüfen das Vorzeichen. Nur Geraden mit negativen Werten müssen beachtet werden.<br />
<img src='http://s0.wp.com/latex.php?latex=++d_h+%3D+%5Coverrightarrow%7Bv%7D+%5Ccdot+%5Coverrightarrow%7Bn_%7Bg%2C0%7D%7D++&#038;bg=ffffff&#038;fg=000000&#038;s=3' alt='  d_h = \overrightarrow{v} \cdot \overrightarrow{n_{g,0}}  ' title='  d_h = \overrightarrow{v} \cdot \overrightarrow{n_{g,0}}  ' class='latex' /></p>
<p><a name="demo"></a><br />
<h5>Demo und Quellcode</h5>
<p>Wer das alles einfach mal ausprobieren will, oder ein wenig Quellcode dazu sehen will, dem empfehle ich mein Demoprogramm hierzu anzuschauen :<br />
<a href="http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-2-demo/">Demonstrationsprogramm zu diesem Teil</a></p>
<p>Allerdings ist es damit noch nicht getan, denn es gibt Situationen wo dieser einfache Ansatz nicht ausreicht. Momentan behandeln wir die Begrenzungskante nämlich als Gerade und nicht als begrenzte Strecke mit Start- und Endpunkt. Das Demoprogramm verdeutlicht dies noch einmal.</p>
<p><a href="http://xaedes.de/blog/2011/02/06/bewegung-mit-kollisionserkennung-teil-3/">Was dazu beachtet werden muss zeige ich im nächsten Teil.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bewegung mit Kollisionserkennung Teil 1</title>
		<link>http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-1/</link>
		<comments>http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-1/#comments</comments>
		<pubDate>Fri, 04 Feb 2011 00:27:36 +0000</pubDate>
		<dc:creator><![CDATA[xaedes]]></dc:creator>
				<category><![CDATA[Kaufhausschlacht]]></category>

		<guid isPermaLink="false">http://xaedes.de/blog/?p=432</guid>
		<description><![CDATA[Teil 1 &#8211; Einführung Teil 2 &#8211; Kollision mit Gerade Teil 2 &#8211; Kollision mit Gerade &#8211; Demoprogramm Teil 3 &#8211; Kollision mit Strecke Teil 3 &#8211; Kollision mit Strecke &#8211; Demoprogramm Momentan arbeite ich daran eine sinnvolle Kollisionserkennung bei den Bewegungen zu implementieren. Zum Berechnen einer korrekten Bewegung habe ich die Welt folgendermaßen modelliert: [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><a href="http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-1/"><strong>Teil 1 &#8211; Einführung</strong></a><br />
<a href="http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-2/">Teil  2 &#8211; Kollision mit Gerade</a><br />
<a href="http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-2-demo/">Teil 2 &#8211; Kollision mit Gerade &#8211; Demoprogramm</a><br />
<a href="http://xaedes.de/blog/2011/02/06/bewegung-mit-kollisionserkennung-teil-3/">Teil 3 &#8211; Kollision mit Strecke</a><br />
<a href="http://xaedes.de/blog/2011/02/06/bewegung-mit-kollisionserkennung-teil-3-demo/">Teil 3 &#8211; Kollision mit Strecke &#8211;  Demoprogramm</a></p>
<p>Momentan arbeite ich daran eine sinnvolle Kollisionserkennung bei den Bewegungen zu implementieren.<br />
Zum Berechnen einer korrekten Bewegung habe ich die Welt folgendermaßen modelliert:<br />
Die Regale, oder später auch andere behindernde Objekte, bekommen eine BoundingBox, in die die Figuren sinnvollerweise nicht eindringen können sollten.<br />
In folgenden Screenshots habe ich mal eine solche BoundingBox verdeutlicht und im zweiten Bild gezeigt was nicht passieren sollte.</p>
<p><img src="http://xaedes.de/blog/wp-content/uploads/Bildschirmfoto1-150x150.png" alt="" title="Bildschirmfoto1" width="150" height="150" class="alignnone size-thumbnail wp-image-439" /> <img src="http://xaedes.de/blog/wp-content/uploads/Bildschirmfoto2-150x150.png" alt="" title="Bildschirmfoto2" width="150" height="150" class="alignnone size-thumbnail wp-image-440" /></p>
<p>Die BoundingBox besteht nun aus einzelnen Begrenzungskanten (Linien) und die Figur habe ich als Kreis abstrahiert:<br />
<img src="http://xaedes.de/blog/wp-content/uploads/bild1.png" alt="" title="bild1" width="579" height="419" class="alignnone size-full wp-image-433" /></p>
<p><img src='http://s0.wp.com/latex.php?latex=s&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='s' title='s' class='latex' /> ist dabei die Position der Figur. <br />
<img src='http://s0.wp.com/latex.php?latex=v&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='v' title='v' class='latex' /> ist der Vektor, der der gewünschten Bewegung der Figur entspricht. Er ist bestimmt durch Richtung und Länge. <br />
<img src='http://s0.wp.com/latex.php?latex=p_%7BL1%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='p_{L1}' title='p_{L1}' class='latex' /> und <img src='http://s0.wp.com/latex.php?latex=p_%7BL2%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='p_{L2}' title='p_{L2}' class='latex' /> sind Endpunkte einer Begrenzungskante, welche nicht überschritten werden sollte. </p>
<p>Würde die Bewegung wie angefordert ausgeführt, hätten wir folgendes Ergebnis:<br />
<img src="http://xaedes.de/blog/wp-content/uploads/bild2.png" alt="" title="bild2" width="579" height="419" class="alignnone size-full wp-image-434" /></p>
<p><img src='http://s0.wp.com/latex.php?latex=z+&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='z ' title='z ' class='latex' /> ist dabei die Position der Figur nach der Bewegung (das <strong>Z</strong>iel). </p>
<p>Wie man unschwer erkennt hat die Figur in diesem Fall die Begrenzungskante nicht beachtet und ist an einer ungültigen Position. </p>
<p>Jetzt müssen wir wissen was bei einer solchen Kollision getan werden soll und wie sich die Figur verhalten soll. Es wäre zum einen möglich eine elastische Kollision mit Bewegungsreflektion, wie bei Billiardkugeln die von der Bande abprallen, zu simulieren, oder wie in diesem Kontext besser, eine unelastische Kollision. Dabei wird einfach nur soweit &#8222;gegangen&#8220; wie möglich. Die Bewegung wird abgeschnitten und Bewegungsenergie geht dabei verloren. Steht man im Spiel z.B. neben einem Regal und versucht in die Richtung des Regals zu gehen, sollte einfach nichts passieren. Das ist das gewünschte Verhalten.<br />
Möchte man eine solche perfekt unelastische Kollision erreichen, ist eine Platzierung wie hier veranschaulicht gesucht.<br />
<img src="http://xaedes.de/blog/wp-content/uploads/bild3a.png" alt="" title="bild3a" width="579" height="419" class="alignnone size-full wp-image-435" />.</p>
<p>Gesucht ist also die korrigierte Zielposition <img src='http://s0.wp.com/latex.php?latex=z%26%238216%3B&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='z&#8216;' title='z&#8216;' class='latex' />.</p>
<p><a href="http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-2/">Wie man diese ausrechnet zeige ich im nächsten Teil.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://xaedes.de/blog/2011/02/04/bewegung-mit-kollisionserkennung-teil-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Kaufhausschlacht &#8211; Update</title>
		<link>http://xaedes.de/blog/2011/02/02/kaufhausschlacht-update-2/</link>
		<comments>http://xaedes.de/blog/2011/02/02/kaufhausschlacht-update-2/#comments</comments>
		<pubDate>Wed, 02 Feb 2011 21:04:42 +0000</pubDate>
		<dc:creator><![CDATA[xaedes]]></dc:creator>
				<category><![CDATA[Kaufhausschlacht]]></category>

		<guid isPermaLink="false">http://xaedes.de/blog/?p=404</guid>
		<description><![CDATA[So, mal wieder ein kleines Update. Zuletzt habe ich an eine Regal gebaut. Dieses sieht man hier: win-02.02.2011-21.51 Bewegung mit den Pfeiltasten ist erstmals auch möglich.]]></description>
				<content:encoded><![CDATA[<p>So, mal wieder ein kleines Update.<br />
<div id="attachment_405" style="width: 74px" class="wp-caption alignnone"><a href="http://xaedes.de/blog/wp-content/uploads/haehnchen.png"><img src="http://xaedes.de/blog/wp-content/uploads/haehnchen.png" alt="" title="haehnchen" width="64" height="64" class="size-full wp-image-405" /></a><p class="wp-caption-text">Hähnchenkeule</p></div></p>
<p>Zuletzt habe ich an eine Regal gebaut. Dieses sieht man hier: <a href='http://xaedes.de/blog/wp-content/uploads/win-02.02.2011-21.51.zip'>win-02.02.2011-21.51</a> </p>
<p>Bewegung mit den Pfeiltasten ist erstmals auch möglich.</p>
]]></content:encoded>
			<wfw:commentRss>http://xaedes.de/blog/2011/02/02/kaufhausschlacht-update-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Kaufhausschlacht &#8211; Update</title>
		<link>http://xaedes.de/blog/2011/01/26/kaufhausschlacht-update/</link>
		<comments>http://xaedes.de/blog/2011/01/26/kaufhausschlacht-update/#comments</comments>
		<pubDate>Wed, 26 Jan 2011 14:42:03 +0000</pubDate>
		<dc:creator><![CDATA[xaedes]]></dc:creator>
				<category><![CDATA[Kaufhausschlacht]]></category>

		<guid isPermaLink="false">http://xaedes.de/blog/?p=391</guid>
		<description><![CDATA[Ich habe zur Zeit viel mit Uni zu tun und daher leider nicht so viel Zeit für Kaufhausschlacht. Trotzdem gibt es jetzt mal ein kleines Update. Aber noch viel interessanter ist eine neue Version zum Ausprobieren. Die zweite Figur ist da schon drin und nen Cursor. EInfach mal ausprobieren : win-26.01.2011-15.57]]></description>
				<content:encoded><![CDATA[<p>Ich habe zur Zeit viel mit Uni zu tun und daher leider nicht so viel Zeit für Kaufhausschlacht. Trotzdem gibt es jetzt mal ein kleines Update.</p>

<a href='http://xaedes.de/blog/2011/01/26/kaufhausschlacht-update/figur-2/'><img width="64" height="64" src="http://xaedes.de/blog/wp-content/uploads/figur1.png" class="attachment-thumbnail" alt="Naiver Entwurf" /></a>
<a href='http://xaedes.de/blog/2011/01/26/kaufhausschlacht-update/figur/'><img width="80" height="80" src="http://xaedes.de/blog/wp-content/uploads/figur.png" class="attachment-thumbnail" alt="Mal eben mit Inkscape zusammen geklickt" /></a>
<a href='http://xaedes.de/blog/2011/01/26/kaufhausschlacht-update/figurmitkorper/'><img width="99" height="120" src="http://xaedes.de/blog/wp-content/uploads/figurmitkörper.png" class="attachment-thumbnail" alt="Und noch einen Körper spendiert. Gefällt mir schon besser" /></a>

<p>Aber noch viel interessanter ist eine neue Version zum Ausprobieren.</p>
<p>Die zweite Figur ist da schon drin und nen Cursor.</p>
<p>EInfach mal ausprobieren : <a href="http://xaedes.de/blog/wp-content/uploads/win-26.01.2011-15.57.zip">win-26.01.2011-15.57</a></p>
]]></content:encoded>
			<wfw:commentRss>http://xaedes.de/blog/2011/01/26/kaufhausschlacht-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Das Programmieren</title>
		<link>http://xaedes.de/blog/2011/01/09/das-programmieren/</link>
		<comments>http://xaedes.de/blog/2011/01/09/das-programmieren/#comments</comments>
		<pubDate>Sun, 09 Jan 2011 16:17:01 +0000</pubDate>
		<dc:creator><![CDATA[xaedes]]></dc:creator>
				<category><![CDATA[Kaufhausschlacht]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[kaufhausschlacht]]></category>
		<category><![CDATA[sfml]]></category>

		<guid isPermaLink="false">http://xaedes.wordpress.com/?p=198</guid>
		<description><![CDATA[Da ich bereits einige Ideen gesammelt habe und das Konzept schon genügend Gestalt angenommen hat, war ich der Meinung, dass mal langsam mit dem Programmieren anfangen könnte. Entschieden habe ich mich für eine Verwendung von C++, KDevelop, SDL, Cairo und CMake. Und puh&#8230; Das einzige was ich bis jetzt geschafft habe ist ein paar simple [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Da ich bereits einige Ideen gesammelt habe und das Konzept schon genügend Gestalt angenommen hat, war ich der Meinung, dass mal langsam mit dem Programmieren anfangen könnte.</p>
<p>Entschieden habe ich mich für eine Verwendung von <strong>C++</strong>, <strong>KDevelop</strong>, <strong>SDL</strong>, <strong>Cairo</strong> und <strong>CMake</strong>.<br />
Und puh&#8230; Das einzige was ich bis jetzt geschafft habe ist ein paar simple SDL und Cairo und jetzt auch schon Pango (für Textdarstellung) Beispiele darzustellen. Im Endeffekt baue ich mir Wrapper für die ganzen C like Libraries SDL, Cairo und Pango. Probleme hat auch die Verwendung von CMake gemacht, da ich für Cairo und Pango noch zusätzlich CMake Module auftreiben musste. Hab ich mir im Endeffekt von Webkit (http://gitorious.org/webkit/webkit/trees/master/Source/cmake) geklaut.<br />
Das mag alles recht lehrreich sein, und am Ende ist vlt auch alles schön portabel&#8230; <strong>Aber das ist es echt nicht wert.</strong> Mein Ziel für das Spiel Kaufhausschlacht war ein kleines Spiel zu programmieren, was in sich komplett ist und auch zu Ende gestellt werden kann. Wenn ich jetzt aber bereits dabei bin, ein Wrapper Framework zur Bändigung von SDL &amp; Co zu schreiben, kann man absehen WANN das fertig wird. Oder besser gesagt, wann NICHT.</p>
<p>Also habe ich mich jetzt dazu entschieden meine Zeit sinnvoller zu nutzen und nach einer anderen, leichter zu handhabenderen Technologie zu suchen.</p>
<p>Visual C# und XNA wollte ich nicht benutzen, wegen der Windowsabhängigkeit. Allegro hab zwar auch schon Erfahrung, aber da damals irgendwas grundlegend schlecht war, so dass ich es neu implementieren musste, habe ich jetzt keine Lust das nochmal zu probieren.<br />
Also Google auf und nach Alternativen gesucht.</p>
<p>Habe <a href="http://clanlib.org/">clanlib </a> und <a href="http://www.sfml-dev.org/index.php">sfml</a> gefunden. Clanlib hat erst nen schöneren Eindruck gemacht, aber die größere Community, mehr Tutorials und einfachere Quellcodes und der Verwendungsgrad in meinem sozialen Umfeld von sfml sprechen einfach für sich.</p>
<p>Werde mich dann wohl dafür entscheiden.<br />
Also alles was ich hab (ist ja nichts im Endeffekt&#8230;) in die Tonne und neu und frisch geht&#8217;s los!</p>
<p><a href="http://www.sfml-dev.org/index.php"><img class="aligncenter size-full wp-image-199" title="SFML" src="http://xaedes.de/blog/wp-content/uploads/logo.jpg" alt="" width="770" height="200" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://xaedes.de/blog/2011/01/09/das-programmieren/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Konzept</title>
		<link>http://xaedes.de/blog/2011/01/05/konzept/</link>
		<comments>http://xaedes.de/blog/2011/01/05/konzept/#comments</comments>
		<pubDate>Wed, 05 Jan 2011 11:55:35 +0000</pubDate>
		<dc:creator><![CDATA[xaedes]]></dc:creator>
				<category><![CDATA[Kaufhausschlacht]]></category>

		<guid isPermaLink="false">http://xaedes.wordpress.com/?p=92</guid>
		<description><![CDATA[mindeeper Zusätzliche Idee: Einkaufszentrum oder Warenhauses mit mehrere räumlich getrennten Sektionen als Metagame Menü, ähnlich wie bei Lego Starwars / Harry Potter etc]]></description>
				<content:encoded><![CDATA[
<a href='http://xaedes.de/blog/2011/01/05/konzept/dsc01356/'><img width="150" height="150" src="http://xaedes.de/blog/wp-content/uploads/dsc01356-150x150.jpg" class="attachment-thumbnail" alt="DSC01356" /></a>
<a href='http://xaedes.de/blog/2011/01/05/konzept/dsc01357/'><img width="150" height="150" src="http://xaedes.de/blog/wp-content/uploads/dsc01357-150x150.jpg" class="attachment-thumbnail" alt="DSC01357" /></a>
<a href='http://xaedes.de/blog/2011/01/05/konzept/dsc01359/'><img width="150" height="150" src="http://xaedes.de/blog/wp-content/uploads/dsc01359-150x150.jpg" class="attachment-thumbnail" alt="DSC01359" /></a>
<a href='http://xaedes.de/blog/2011/01/05/konzept/dsc01360/'><img width="150" height="150" src="http://xaedes.de/blog/wp-content/uploads/dsc01360-150x150.jpg" class="attachment-thumbnail" alt="DSC01360" /></a>
<a href='http://xaedes.de/blog/2011/01/05/konzept/dsc01361/'><img width="150" height="150" src="http://xaedes.de/blog/wp-content/uploads/dsc01361-150x150.jpg" class="attachment-thumbnail" alt="DSC01361" /></a>

<p><a href="http://www.ludumdare.com/compo/ludum-dare-19/?action=preview&amp;uid=3357">mindeeper</a></p>
<p>Zusätzliche Idee:<br />
Einkaufszentrum oder Warenhauses mit mehrere räumlich getrennten Sektionen als Metagame Menü, ähnlich wie bei Lego Starwars / Harry Potter etc</p>
]]></content:encoded>
			<wfw:commentRss>http://xaedes.de/blog/2011/01/05/konzept/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
