Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 11th, 2004, 7:07 AM   #1
Progejad
Newbie
 
Join Date: Nov 2004
Posts: 2
Rep Power: 0 Progejad is on a distinguished road
I have to do program which calculates x and y couples using next formulas:

x=(40*cos)+60*Math.cos((2/3)*t);

y=(40*sin)-60*Math.sin((2/3)*t);


the output of the program should look something like this:

x | y

1234 | 3456 // x and y results
2234 | 8923
1256 | 9842

"t" should change after 0,01 step (from -10 to 10)
(So in output there should be 2000 couples of x and y + first line x|y)

I tried to program but got only more confused after hours of trying...biggest problem is that "step" thing...and that "t" should change after every step...
I hope there's anyone that could help me ...
Progejad is offline   Reply With Quote
Old Nov 11th, 2004, 9:12 AM   #2
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
Sounds easy enough... Since this is a homework assignment, I'd like to see effort (code) on your end before I contribute code.

The "step" problem, would be a loop with an index variable that increments through from -10 to 10.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Nov 12th, 2004, 3:39 AM   #3
Progejad
Newbie
 
Join Date: Nov 2004
Posts: 2
Rep Power: 0 Progejad is on a distinguished road
/*at the end my code was like that, but x and y were not right (maybe i did something wrong with x and y calculating
http://www.itcollege.ee/~kkoemets/kodused2...l_51b41c47.gif- x and y should be like that*/

//starting my code:   

    public class Hindeline1 {

    public static void main (String [] args) {   

    double x;
    double y;
   
    
    double t;
	

	for (t = -10; t <= (10); t +=0.01) 
	{
	
	double sin=Math.sin(t);
    double cos=Math.cos(t);
	
	x=(40*cos)+60*Math.cos((2/3)*t);
   
    y=(40*sin)-60*Math.sin((2/3)*t);
   
	
	System.out.println (x+ "|" +y);
	}
	}

}//End of code
Progejad is offline   Reply With Quote
Old Nov 13th, 2004, 1:29 AM   #4
drunkenCoder
Newbie
 
drunkenCoder's Avatar
 
Join Date: Nov 2004
Posts: 8
Rep Power: 0 drunkenCoder is on a distinguished road
looks like you got it right to me ... what you wrote calculates x & y correctly (going by the formula you have provided)
drunkenCoder is offline   Reply With Quote
Old Nov 13th, 2004, 11:51 AM   #5
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
Looks good. The code achieves your 2000+1 lines of output.
Drunken coder has confirmed the value is correct... you can plug them into a
calculator to confirm further if needed.



public class Hindeline1
{
 public static void main (String [] args)
 {
   double x;
   double y;
   double t;

   for (t = -10; t <= 10; t += 0.01)
   {
    double sin=Math.sin(t);
    double cos=Math.cos(t);

    x = (40 * cos) + 60 * Math.cos((2/3)*t);
    y = (40 * sin) - 60 * Math.sin((2/3)*t);

    System.out.println(x + " | " + y);
   }
 }
}
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:36 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC