Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Since you are doing this in MATLAB, here is one solution that should work:</p> <pre><code>crossProds = [V1(1)*V2(2)-V1(2)*V2(1) ... V1(1)*V3(2)-V1(2)*V3(1) ... V3(1)*V2(2)-V3(2)*V2(1)]; if (all(crossProds &gt;= 0) || ... (crossProds(1) &lt; 0) &amp;&amp; ~all(crossProds(2:3) &lt; 0)), disp("V3 is between V1 and V2"); else disp("out of the interval"); end </code></pre> <p><strong>EXPLANATION:</strong></p> <p>The cross product between the 2-D vectors <strong>V1</strong> and <strong>V2</strong> is stored in the first element of <strong>crossProds</strong>. This value will be greater than or equal to zero if the counter-clockwise angle between <strong>V1</strong> and <strong>V2</strong> is between 0 and 180 degrees, inclusive. In this case, when <strong>V3</strong> is between <strong>V1</strong> and <strong>V2</strong> in the counter-clockwise direction then the cross products <strong>(V1,V3)</strong> and <strong>(V3,V2)</strong> are also greater than or equal to zero. This explains the first logical check:</p> <pre><code>all(crossProds &gt;= 0) </code></pre> <p>If the counter-clockwise angle between <strong>V1</strong> and <strong>V2</strong> is greater than 180 degrees, then the cross product of these two vectors will be less than zero. In this case, when <strong>V3</strong> is between <strong>V1</strong> and <strong>V2</strong> in the <em>clockwise</em> direction then the cross products <strong>(V1,V3)</strong> and <strong>(V3,V2)</strong> are also less than zero. Therefore, if these cross products are <em>not</em> both less than zero then <strong>V3</strong> must be between <strong>V1</strong> and <strong>V2</strong> in the <em>counter-clockwise</em> direction. This explains the next two logical checks:</p> <pre><code>(crossProds(1) &lt; 0) &amp;&amp; ~all(crossProds(2:3) &lt; 0) </code></pre> <p>The above logical checks should cover all possible situations. The operators || and &amp;&amp; are <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/logicaloperatorsshortcircuit.html" rel="noreferrer">short circuit operators</a> in MATLAB: they will skip the second statements if they are not necessary. For example, if the first statement in an OR is true, there is no reason to check the second statement since only one argument in an OR needs to be true for the result to be true.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload