-3

I have the gradian of 5. When I do inverse tan, I get the answer 0.007. The actual answer is 87.43. What formula do I use to get the right answer?

I did:

textDoub = textDoub / 1.11111111111;
textDoub = Math.atan(Math.toRadians(textDoub));

textDoub is the amount of grad.

dimo414
  • 47,227
  • 18
  • 148
  • 244
Compsci
  • 9
  • 3
  • Are you sure you have a *gradian*? It looks like you're doing operations on *radians*. – Makoto Apr 06 '15 at 23:12
  • You shoul go to http://math.stackexchange.com/ – xsami Apr 06 '15 at 23:13
  • 2
    @xsami: Not necessarily. It's too unclear to say for certain. – Makoto Apr 06 '15 at 23:14
  • So then the division operation on `textDoub` converts it over to a radian, then? Bear in mind that `Math#toRadians` is only considering the radian value of whatever you're passing in. – Makoto Apr 06 '15 at 23:15
  • I get a random number to textDoub – Compsci Apr 06 '15 at 23:16
  • i want it to show me tan inverse in gradians. I am working on a calculator right now – Compsci Apr 06 '15 at 23:16
  • 2
    Plugging your [math into Google](https://www.google.com/search?q=atan%28degrees+to+radians%285%2F%2810%2F9%29%29%29) gives neither `0.0007` nor `87.43`. Please update your question with the actual mathematical equation (including units) you're trying to implement in Java. As is, we don't have enough information to help you. – dimo414 Apr 06 '15 at 23:21
  • Inverse tan of 5 grad IS 87.43. – Compsci Apr 06 '15 at 23:34
  • @dimo414 `atan()` takes a slope and returns an angle. It's the angle that needs converting. Not the slope. – candied_orange Apr 07 '15 at 01:45
  • @CandiedOrange I simply took what OP posted and put it into Google. If the result of that transcription is incorrect or ambiguous, that's the point I was trying to make. If OP posts a Google/Wolfram-Alpha/etc. link showing exactly the calculation they're trying to implement in Java it will make the question much clearer, and more clearly on-topic for StackOverflow. As is, I assume the downvotes are due to this ambiguity. – dimo414 Apr 07 '15 at 02:28

1 Answers1

1

You don't.

The gradian is a unit of plane angle, equivalent to 1⁄400 of a turn. It is also known as gon, grad, or grade. One grad equals 9⁄10 of a degree or π⁄200 of a radian.

A gradian is an angle. Whether in degrees, radians, or gradians, inv tan takes a slope and returns an angle. Doing an inv tan of a gradian doesn't make sense.

gradians = 200 / Math.PI * Math.atan(slope)

If you're going to be working with gradians much, having conversion methods might be handy.

double gradianToRadian(double gradian) {
    return gradians * Math.PI / 200;
}

double radianToGradian(double radian) {
    return radians / Math.PI * 200;
}

Putting that together gives:

gradians = radianToGradian( Math.atan(slope) )

Testing your example problem:

assertEquals(87.43, radianToGradian( Math.atan(5) ), 0.001);

assertEquals(gradianToRadian(87.43), Math.atan(5), 0.001);

assertEquals(Math.tan( gradianToRadian(87.43) ), 5, 0.001);

I think the numbers you gave are correct. Just mislabeled. 5 is a slope not a gradian. 87.43 is the gradian.

Gradians are angles. You don't do an "inverse tan of a gradian". You convert to gradian after doing an inverse tan on a slope.

Community
  • 1
  • 1
candied_orange
  • 7,036
  • 2
  • 28
  • 62
  • Doesn't return the needed value. – Compsci Apr 06 '15 at 23:25
  • atan should return a radian value rather than accept one. Should the conversion be done on the functions result? – Atreys Apr 06 '15 at 23:32
  • In a calculator, there is deg, rad, and grad. I make it mode grad and enter inverse tan of 5. I get the answer 87.43. In my program, i try to do the same. It;s in grad mode and I receive a number, example, 5. I don't understand what to do next to get the right answer, 87.43 – Compsci Apr 06 '15 at 23:36
  • @Compsci 5 is not the gradian here. 87.43 is the gradian. Gradians are angles. Angles are what come out of inv tan. Slopes are what go into inv tan. – candied_orange Apr 07 '15 at 07:52