Finding Tree Height Using Simple Geometry and Java Coding

  • Context: Java 
  • Thread starter Thread starter obeying
  • Start date Start date
  • Tags Tags
    Coding Geometry Java
Click For Summary
SUMMARY

The discussion focuses on calculating the height of a tree using simple geometry and Java programming. The formula used is tan(angleElevation) = treeHeight / shadowLength, where angleElevation is given in radians. The initial Java code provided encounters an error due to the incorrect use of the tangent function, which should be referenced as Math.tan. After correcting this, the code successfully computes the tree height.

PREREQUISITES
  • Understanding of basic trigonometry, specifically the tangent function.
  • Familiarity with Java programming language and syntax.
  • Knowledge of the Math class in Java for mathematical functions.
  • Ability to work with angles in radians versus degrees.
NEXT STEPS
  • Explore Java Math class functions for advanced mathematical operations.
  • Learn about converting degrees to radians in Java programming.
  • Investigate error handling in Java to manage runtime exceptions.
  • Study geometric applications of trigonometry in real-world scenarios.
USEFUL FOR

Java developers, students learning programming, and anyone interested in applying geometry in coding projects.

obeying
Messages
8
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.

What I have so far:

import java.util.Scanner;
import java.lang.Math;

public class TreeHeight {
public static void main(String [] args) {
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 = shadowLength * tan(angleElevation);

System.out.print("Tree height: ");
System.out.println(treeHeight);

return;
}
}
Error that I'm getting:

TreeHeight.java:14: cannot find symbol
symbol : method tan(double)
location: class TreeHeight
treeHeight = shadowLength * tan(angleElevation);

1 error
 
Technology news on Phys.org
obeying said:
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.

What I have so far:

import java.util.Scanner;
import java.lang.Math;

public class TreeHeight {
public static void main(String [] args) {
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 = shadowLength * tan(angleElevation);

System.out.print("Tree height: ");
System.out.println(treeHeight);

return;
}
}
Error that I'm getting:

TreeHeight.java:14: cannot find symbol
symbol : method tan(double)
location: class TreeHeight
treeHeight = shadowLength * tan(angleElevation);

1 error

Hey obeying! Welcome to MHB! ;)

I believe that should be [M]Math.tan[/M].
That is, the tangent function is part of the Math package and that needs to be specified.
 
I like Serena said:
Hey obeying! Welcome to MHB! ;)

I believe that should be [M]Math.tan[/M].
That is, the tangent function is part of the Math package and that needs to be specified.

Awesome! Thank you it worked!
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
18K
Replies
3
Views
3K
Replies
1
Views
8K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
9
Views
2K