<< Chapter < Page Chapter >> Page >
y = x*x
Listing 6 . The method named function for Parabola01. double function(double xVal){ double yVal = xVal*xVal;return yVal; }//end function

A plot of the output of the method named function would look like the curve shown in Figure 7 with no offsets if the x and y scaling values were set to one-half the width and height of the world respectively.

Figure 7. Parabola with zero offsets.

Missing image

It will be instructive to see how this program uses offsets and scaling values to transform the image shown in Figure 7 into the image shown in Figure 6 .

Drawing parameters for Parabola01

The code fragment shown in Listing 7 shows the drawing parameters that were used to produce the output shown in Figure 6 .

Listing 7 . Drawing parameters for Parabola01. double xOff = 0.25;//offset relative to 1.0 double yOff = -0.25;double xScale = 0.75*world.getWidth()/2; double yScale = 1.25*world.getHeight()/2;

Drawing parameters with zero offsets

The parameters that were used to produce the output shown in Figure 7 are shown below:

double xOff = 0.0;//offset relative to 1.0 double yOff = -0.0;double xScale = 1.0*world.getWidth()/2; double yScale = 1.0*world.getHeight()/2;

Note in particular that the offsets given by xOff and yOff are set to zero and the scale factors given by xScale and yScale are one-half the width and height of the world respectively.

Changing the offset values

Increasing the offsets for xOff and yOff to 0.25 and -0.25 respectively as shown in Figure 7 and making no other changes produces the output shown in Figure 8

Figure 8. A parabola with offsets.

Missing image

In comparison with Figure 7 , changing the value of xOff to 0.25 caused the peak to move to the right (positive direction) one-fourth of the way from the center origin to the right edge of the world. (That change also caused a portion of the curve to fall outside the right boundary of the world.)

Similarly, changing the value of yOff to -0.25 caused the peak to move up (negative direction) one-fourth of the way from the center origin to the top edge of the world.

Changing the scale factors

Following that, changing the values of xScale and yScale to the values shown in Listing 7 produces the graphic output shown in Figure 6 . The change in xScale decreased the total width of the curve and prevented it from exceeding the rightmost boundary of theworld. The change in yScale increased the overall height of the curve causing it to almost touch the lower boundary of the world.

Draw the parabolic function in BLUE

The code in Listing 8 draws the blue parabolic function shown in Figure 6 .

Listing 8 . Draw the parabolic function in BLUE. double yVal = 0; int row = 0;int col = 0; double xVal = -1;turtle.setPenColor(Color.BLUE); for(int cnt=0; cnt<=100;cnt++,xVal += 0.02){ //Get a y-value for the given x-value.yVal = function(xVal); //Apply the offsets and scale the resultscol = (int)((xOff+xVal)*xScale); row = (int)((yOff+yVal)*yScale);//Move to the first point without drawing a line because the// pen is not down. Translate the origin to the center in the // process.turtle.moveTo(col + world.getWidth()/2, row + world.getHeight()/2);//Lower the pen in order to draw a line from each point to the // next point.turtle.penDown(); }//end for loop}//end run method

Questions & Answers

how do you get the 2/50
Abba Reply
number of sport play by 50 student construct discrete data
Aminu Reply
width of the frangebany leaves on how to write a introduction
Theresa Reply
Solve the mean of variance
Veronica Reply
Step 1: Find the mean. To find the mean, add up all the scores, then divide them by the number of scores. ... Step 2: Find each score's deviation from the mean. ... Step 3: Square each deviation from the mean. ... Step 4: Find the sum of squares. ... Step 5: Divide the sum of squares by n – 1 or N.
kenneth
what is error
Yakuba Reply
Is mistake done to something
Vutshila
Hy
anas
hy
What is the life teble
anas
hy
Jibrin
statistics is the analyzing of data
Tajudeen Reply
what is statics?
Zelalem Reply
how do you calculate mean
Gloria Reply
diveving the sum if all values
Shaynaynay
let A1,A2 and A3 events be independent,show that (A1)^c, (A2)^c and (A3)^c are independent?
Fisaye Reply
what is statistics
Akhisani Reply
data collected all over the world
Shaynaynay
construct a less than and more than table
Imad Reply
The sample of 16 students is taken. The average age in the sample was 22 years with astandard deviation of 6 years. Construct a 95% confidence interval for the age of the population.
Aschalew Reply
Bhartdarshan' is an internet-based travel agency wherein customer can see videos of the cities they plant to visit. The number of hits daily is a normally distributed random variable with a mean of 10,000 and a standard deviation of 2,400 a. what is the probability of getting more than 12,000 hits? b. what is the probability of getting fewer than 9,000 hits?
Akshay Reply
Bhartdarshan'is an internet-based travel agency wherein customer can see videos of the cities they plan to visit. The number of hits daily is a normally distributed random variable with a mean of 10,000 and a standard deviation of 2,400. a. What is the probability of getting more than 12,000 hits
Akshay
1
Bright
Sorry i want to learn more about this question
Bright
Someone help
Bright
a= 0.20233 b=0.3384
Sufiyan
a
Shaynaynay
How do I interpret level of significance?
Mohd Reply
It depends on your business problem or in Machine Learning you could use ROC- AUC cruve to decide the threshold value
Shivam
how skewness and kurtosis are used in statistics
Owen Reply
yes what is it
Taneeya
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?

Ask