Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When I run your code, the stack trace I get is:</p> <pre><code>Traceback (most recent call last): File "md.py", line 22, in &lt;module&gt; analyze_the_shape([(0, 0), (0, 4.0), (4.0, 4.0), (4.0, 0)]) File "md.py", line 18, in analyze_the_shape angle = math.degrees(math.acos(cos_angle)) ValueError: math domain error </code></pre> <p>I know <code>math.acos</code> only accepts values such that <code>-1.0 &lt;= x &lt;= 1.0</code>. If I print out <code>cos_angle &lt; -1.0</code> right before the line <code>angle = math.degrees(math.acos(cos_angle))</code>, it prints <code>True</code>. If I print out <code>cos_angle</code>, it prints <code>-1.0</code>.</p> <p>I'm guessing the issue here is that the way Python stores <code>cos_angle</code> isn't perfect, and that the value you generate for <code>cos_angle</code> is just barely less than <code>-1.0</code>.</p> <p>Perhaps it would be better, if, instead of checking <code>abs(angle - 90.0) &lt; 0.001</code>, you checked if <code>abs(cos_angle) &lt; 0.001</code>.</p> <p><strong>Edit</strong>:</p> <p>I think you have an error in this line:</p> <pre><code>cos_angle = float((hypo**2 - (d3)**2 + (d4)**2) / ((-2.0)*(d4)*(d3))) </code></pre> <p>It probably should be:</p> <pre><code>cos_angle = float((hypo**2 - ((d3)**2 + (d4)**2)) / ((-2.0)*(d4)*(d3))) </code></pre> <p>Note the extra parens around <code>(d3)**2 + (d4)**2</code>. This makes sure that addition is done <em>before</em> you subtract that quantity from <code>hypo**2</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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