Computing height given shadow length and angle of elevation

Click For Summary
SUMMARY

The discussion focuses on calculating the height of an object using its shadow length and angle of elevation through the formula: tan(angleElevation) = treeHeight / shadowLength. The user encountered an error in their C++ implementation, where the calculated tree height did not match the expected value. The correct formula for computing tree height is treeHeight = shadowLength * tan(angleElevation), which resolves the discrepancy in the output. The conversation also emphasizes the importance of using descriptive thread titles for better forum organization and SEO.

PREREQUISITES
  • Understanding of basic trigonometry, specifically tangent functions
  • Familiarity with C++ programming language
  • Knowledge of radians and degrees conversion
  • Experience with debugging and testing code outputs
NEXT STEPS
  • Study the C++ math library functions for trigonometric calculations
  • Learn about angle conversions between radians and degrees
  • Explore error handling and debugging techniques in C++
  • Research best practices for writing effective forum thread titles
USEFUL FOR

Students learning trigonometry, C++ programmers, educators teaching geometry, and forum users looking to improve their online communication skills.

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.
 
Technology 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!
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
12K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
Replies
9
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K