Finding Tree Height Using Simple Geometry and Java Coding

In summary, the code computes the height of a tree using the shadow length and angle of elevation, and uses the tangent function from the Math package to do so.
  • #1
obeying
8
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
  • #2
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.
 
  • #3
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!
 

1. What is the relationship between geometry and Java coding?

The relationship between geometry and Java coding is that Java coding can be used to solve geometric problems and create geometric shapes. Java has built-in libraries for mathematical operations, making it a useful tool for working with geometric concepts and calculations.

2. How does Java coding help with geometry?

Java coding can help with geometry by providing tools and functions for performing geometric calculations and creating geometric shapes. By using Java's libraries for mathematical operations, it becomes easier to solve complex geometric problems and visualize geometric concepts.

3. Can Java coding be used to create 3D geometric shapes?

Yes, Java coding can be used to create 3D geometric shapes. Java has libraries for 3D graphics, such as Java3D and JOGL, which allow for the creation of 3D shapes and animations. With these libraries, it is possible to create complex 3D geometric shapes and visualize them in a virtual environment.

4. Is knowledge of geometry necessary for Java coding?

Knowledge of geometry is not necessary for Java coding, but it can be helpful for understanding and solving certain problems. Some basic understanding of geometric concepts, such as angles and shapes, can make it easier to work with geometric calculations and create visualizations using Java coding.

5. What are some practical applications of combining geometry and Java coding?

There are many practical applications of combining geometry and Java coding. Some examples include creating 2D and 3D graphics for video games and simulations, designing architectural structures, and creating visualizations for scientific data. Java's ability to perform complex calculations and create visualizations makes it a useful tool for many industries that involve geometry.

Similar threads

  • Programming and Computer Science
Replies
2
Views
17K
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
1
Views
753
  • Programming and Computer Science
Replies
1
Views
7K
  • Programming and Computer Science
Replies
3
Views
3K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
1
Views
2K
Back
Top