I have the correct code for the problem 7 in chapter 9 of "The art and science of java", which I found from a solutions manual online. Images of the page describing the problem are provided in attachment. however, I cannot tell how this programmer
found the correct values to pass to the GArc and GLine methods in order to draw the heart picture. I know it has something to do with trigonometry and fact that Math.sqrt(2) is the factor you multiply the side of a right triangle by to find the hypotenuse,
but I cannot see why the solution has those values for dx, height, and so forth. I realize this may be more of a math question than concerning java, but any help would be useful.
Obviously the ACM drawing classes are an extension of Swing classes; I do not have them.
Does anything go wrong when you draw the heart? Did you work out the coordinates on paper before trying to program them? Here are some possible coordinates for the square:-In which case the centres of the circles will be 30, 30 and 70, 30.
here is my latest attempt. I tried setting the midpoint of the circle each arc is drawn from to exactly halfway between the points you display above. So the midpoint of the left arc would be (30, 35) for the left arc, and to define the upper left corner of the rectangle bounding the arc, I just subtract the radius, from the x and y coordinates, as seen below:
The arcs are still not connecting with the rays below. I have tried this with multiple sizes. I think the secret is to define just one number for either length To Ray (distance from center of the diamond to diamond vertex, or the radius of each circle that defines the left and right arcs, then just make all other coordinates functions of that, as seen in the official answer I originally posted. But I cannot tell how the official answer made the calculations. Nothing I remember on geometry tells me what, if any, relation there is between the radius of the circles making the left and right arcs and the rays that connect with them.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop