![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2004
Posts: 2
Rep Power: 0
![]() |
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 ... |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() ![]() |
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." |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Nov 2004
Posts: 2
Rep Power: 0
![]() |
/*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 |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Nov 2004
Posts: 8
Rep Power: 0
![]() |
looks like you got it right to me ... what you wrote calculates x & y correctly (going by the formula you have provided)
|
|
|
|
|
|
#5 |
|
Programming Guru
![]() ![]() ![]() |
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." |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|