Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that plots the sine function in red and the cosecant function in blue. Hints: The above scene is 800 pixels wide and

Write a program that plots the sine function in red and the cosecant function in blue.

Hints: The above scene is 800 pixels wide and 600 pixels tall. On the x-axis, -2 is at pixel (200, 300), the center of the axis is at (400, 300), and 2 is at (600, 300). Draw your text for these points near (but not directly on) these coordinates. The Unicode for is \u03c0. To display -2, use Text(x, y, - 2\u03c0). My program used Font.font("Georgia", 25) as the font for each of the Text objects. (Recall that you use the setFont() on a Text object to set its font.

For a trigonometric function like Math.sin(x), x is in radians. You can use the following loop to add the points to a polyline for the sine curve:

Polyline sineCurve = new Polyline();

ObservableList list = sineCurve.getPoints();

for (double x = -340; x <= 340; x++) {

list.add(x + 400);

list.add(300 100 * Math.sin((x / 200.0) * 2 * Math.PI));

}

Your program can draw the entire sine curve as a single polyline. Remember to set its color to red.

The cosecant is a little trickier. Recall from your pre-calculus course that the cosecant (csc) function is defined by csc(x) = 1 / sin(x). Because the cosecant curve approaches positive and negative infinity, alternately, on each side of each vertical asymptote, it will not work to draw the cosecant curve as a single polyline. Your program will need to draw eight different polylines to represent the cosecant. Several approaches to this part of the assignment will work. My approach is to have the program check when the sign of the y-coordinate of the cosecant curve changes. When it changes, my program adds to the scene the current polyline and then creates a new, empty polyline for the next part of the curve. Use whatever approach you think is reasonable, as long as your code is reasonably clear and concise. Remember to set the color to blue.

So I am having trouble with this question. Any help would be appreciated. Thanks!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

4 5 - : 8 and 4 5 / / 8 produces the result five

Answered: 1 week ago

Question

10-9 How have social technologies changed e-commerce?

Answered: 1 week ago