Computing height given shadow length and angle of elevation

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 18K views
needOfHelpCMath
Messages
70
Reaction score
0
Simple geometry can compute the height of an object from the object's shadow length and shadow angle using the formula: tan(angleElevation) = treeHeight / shadowLength. Given the shadow length and angle of elevation, compute the tree height.
Code:
#include <iostream>
#include <cmath>
using namespace std;

int main( ) {
   double treeHeight     = 0.0;
   double shadowLength   = 0.0;
   double angleElevation = 0.0;

   angleElevation = 0.11693706; // 0.11693706 radians = 6.7 degrees
   shadowLength   = 17.5;

   
  treeHeight = cos(shadowLength) / angleElevation ;

   
   cout << "Tree height: " << treeHeight << endl;

   return 0;
}

My outputs

✖ Testing with shadowLength = 17.5, angleElevation = 0.11693706
Expected value: 2.05578
Your value: 1.87656
Tests aborted.
 
Physics news on Phys.org
Re: What heck i am doing wrong?

treeHeight = shadowLength * tan(angleElevation)
 
Please use thread titles that describe the posted problem...a title like "What the heck am I doing wrong?" doesn't tell people browsing the forums anything at all about what's being asked in the thread. :D

Not only will this increase the chances that you will get responses, but it improves the organization of our site and SEO as well. Everyone wins!