•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 391,548 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,519 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 5764 | Replies: 27
![]() |
•
•
Join Date: Jul 2005
Location: South East Asia , Singapore
Posts: 52
Reputation:
Rep Power: 4
Solved Threads: 0
There are two things which I didn't or could not achieve with using maths.cos() from Java.
First - When I calculate cos90 or cos270, it gives me absurb values. It should be 0. Meaning it cannot calculate if the angle lies on X axis.
I tested with 91 or 271, gives a near 0 which is correct.
Second - I was figuring how do I include the number of terms to be calculated with my Cosine formula....
Lastly, I am using JFrames as my GUI and I can only properly exit from my menu bar. And not from the X button at top RH corner.
I would appreciate hints or guidance in solving the above 3 issues. Thank you so much people!
First - When I calculate cos90 or cos270, it gives me absurb values. It should be 0. Meaning it cannot calculate if the angle lies on X axis.
I tested with 91 or 271, gives a near 0 which is correct.
Second - I was figuring how do I include the number of terms to be calculated with my Cosine formula....
Lastly, I am using JFrames as my GUI and I can only properly exit from my menu bar. And not from the X button at top RH corner.
I would appreciate hints or guidance in solving the above 3 issues. Thank you so much people!
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,646
Reputation:
Rep Power: 18
Solved Threads: 191
If you properly set up the application you can exit the application normally (with JVM shutdown) by using the operating system supplied features (like the close icon in the window corner) as well.
Something like in your main application frame should work wonders.
Something like
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
•
•
Join Date: Jun 2004
Posts: 604
Reputation:
Rep Power: 6
Solved Threads: 6
Hi eveyone,
Use loops and arrays
Richard West
•
•
•
•
Originally Posted by LiBOC
Second - I was figuring how do I include the number of terms to be calculated with my Cosine formula
Use loops and arrays
Richard West
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
•
•
Join Date: Jul 2005
Location: South East Asia , Singapore
Posts: 52
Reputation:
Rep Power: 4
Solved Threads: 0
Yea, I had convert it into radians before putting it back into the default math.cos() method... but only 270 and 90 are wrong values!
•
•
•
•
Originally Posted by dandan
Math.cos is using angles in radians. Try Math.cos(Math.toRadians(90)).
Second - I don't understand.
Try jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,646
Reputation:
Rep Power: 18
Solved Threads: 191
no, the rest is wrong as well (though it is possible that by some chance a few distinct values might happen to be identical it's unlikely).
But they're less obviously wrong unless you know what to expect. Do you know the exact cosine of every angle to 10 decimal places without looking them up?
But they're less obviously wrong unless you know what to expect. Do you know the exact cosine of every angle to 10 decimal places without looking them up?
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
•
•
Join Date: Jul 2005
Location: South East Asia , Singapore
Posts: 52
Reputation:
Rep Power: 4
Solved Threads: 0
Thanks.
I used the calculator program on my WinXP to counter check with my Java App. It is exactly correct. Only for 90 and 270 degrees. I also had converted them to radians.
And also, math.cos() method do not include terms if I am not wrong?
What if I want to write my own cosine formula that include a user-defined number of terms? Rewrite the formula into a java language? Solve the maths equation yourself?
can math.cos() do that?
I used the calculator program on my WinXP to counter check with my Java App. It is exactly correct. Only for 90 and 270 degrees. I also had converted them to radians.
And also, math.cos() method do not include terms if I am not wrong?
What if I want to write my own cosine formula that include a user-defined number of terms? Rewrite the formula into a java language? Solve the maths equation yourself?
can math.cos() do that?
•
•
•
•
Originally Posted by jwenting
no, the rest is wrong as well (though it is possible that by some chance a few distinct values might happen to be identical it's unlikely).
But they're less obviously wrong unless you know what to expect. Do you know the exact cosine of every angle to 10 decimal places without looking them up?
•
•
Join Date: Jun 2004
Location: H4x0rville
Posts: 2,105
Reputation:
Rep Power: 9
Solved Threads: 18
What are the values you are getting for 90 and 270? Shouldn't they both be 0 according to the unit circle?
•
•
•
•
What if I want to write my own cosine formula that include a user-defined number of terms? Rewrite the formula into a java language? Solve the maths equation yourself?
What do u want to do? I still have no clue? What do u mean by number terms? You aren't making much sense. Please give us an example. R u trying to solve generic equasions like:
•
•
•
•
1/2cos x =75
•
•
•
•
1/2cos(3x) -5cos = 45
Member of: F-ugly code club
Join today don't delay!
Join today don't delay!
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,646
Reputation:
Rep Power: 18
Solved Threads: 191
•
•
•
•
Originally Posted by server_crash
What are the values you are getting for 90 and 270? Shouldn't they both be 0 according to the unit circle?
yes, and when using radials they won't be 0 but roughly -.45 and +.98 respectively.
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
- Previous Thread: help
- Next Thread: error when compiling



Linear Mode