• Post Reply Bookmark Topic Watch Topic
  • New Topic

Method Return 0 Value  RSS feed

 
Ranch Hand
Posts: 119
Eclipse IDE Mac VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to calculate a certain value, but it is returning 0 and I'm not sure why. This is a measurement to define the angle from the equator and the center of the sun

 
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does 360/365 equate to?
 
Sheriff
Posts: 22845
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, it's that old integer-division gotcha again! When you write "360/365" in Java that results in an integer value with the remainder from the division thrown away. In other words, in this case it's zero, which isn't what you wanted. You want a double value there, so write "360.0/365.0" instead.

The other gotcha which you haven't hit yet is that the Math.sin() and other trignometric functions want parameters in radians, not degrees. Check the documentation for the Math class to find out how to convert degrees to radians.
 
Derek Smiths
Ranch Hand
Posts: 119
Eclipse IDE Mac VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you guys for your replies -- that fixed the problem. Now, I'm trying to get the local solar time which is defined as the highest point of the sun locally. double lst = LT + tc/60 LT is the local time. Is there a good way to calculate this, or is there a way to get the local time in minutes?

 
Paul Clapham
Sheriff
Posts: 22845
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java 8 you can get a LocalTime object representing now:



Then you can get the hours and minutes from it and do the obvious calculation to get the number of minutes since midnight, which I think is what you want? Only problem is you're then going to have to deal with daylight saving time, which you want to factor out -- I think, anyway. I can't quite tell what your code is supposed to be doing, for example based on the variable names it looks like it's subtracting a longitude from a time... so probably "ltm" doesn't mean what I guessed.
 
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:In Java 8 you can get a LocalTime object representing now:



Then you can get the hours and minutes from it and do the obvious calculation to get the number of minutes since midnight...

Java8 provides two ways for doing that more succinctly.
 
Paul Clapham
Sheriff
Posts: 22845
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:Java8 provides two ways for doing that more succinctly.


I'm not surprised. The pendulum swung from not enough classes for the job in Java 1 to a class for every single different thing in Java 8. I'm very far from understanding all of the new date and time variants.
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect most people will go through the Java® Tutorials, find one way which works for them, and stick to that way for ever.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A few hours ago, I wrote:I suspect most people will go through the Java® Tutorials, find one way which works for them, and stick to that way for ever.
I have just bought a copy of The Psychology of Everyday Things by Donald A Norman.
Page 8 of that book wrote:In England I visited a home with a fancy new Italian washer‑drier combination, with super‑duper multi‑symbol controls, all to do everything you ever wanted to do with the washing and drying of clothes. The husband (an engineering psychologist) said he refused to go near it. The wife (a physician) said she had simply memorized one setting and tried to ignore the rest.
 
Derek Smiths
Ranch Hand
Posts: 119
Eclipse IDE Mac VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Paul, to clarify my code, I am designing a program that will display a graph to continuously update the path of the sun throughout the day and will display it on an FX chart. I have a program that is attached to my arduino that has solar panel data passing (serial connection) to my FX program. The specific method above is to increase the accuracy of the solar position within the local time meridian for the specific region. This website might fill you in, IF you are interested: http://www.pveducation.org/pvcdrom/properties-of-sunlight/solar-time

The ltm value is derived from this method.I know getRawOffset() produces a value in microseconds so, I've converted to hours. I would imagine this is all overkill and I could just define this as a constant, but thought I would give it a go.

 
Paul Clapham
Sheriff
Posts: 22845
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems to me you have to take into account the DST offset for the date and time in question, not just the raw offset (which is the offset which applies whenever DST is applicable), don't you?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!