Java Finding Tree Height Using Simple Geometry and Java Coding

AI Thread Summary
The discussion focuses on calculating the height of a tree using simple geometry, specifically the relationship between the angle of elevation and the length of the shadow. The formula used is tan(angleElevation) = treeHeight / shadowLength. A Java code snippet is provided to implement this calculation, but an error arises due to the incorrect usage of the tangent function. The solution involves using Math.tan to correctly reference the tangent function from the Math package, which resolves the error and allows the program to compute the tree height successfully.
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!
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top