programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Corner point coordinates exercise

Tiberius Marius
Ranch Hand
Posts: 115
3
I found a exercise i already lost 1h+ on and it kind of obsessing me to understand how it can be resolved . My high school math is mostly gone so...

The problem(nr 4.7 /page 152 Intro in Java Programming 10th Edition) is :

(Corner point coordinates) Suppose a pentagon is centered at (0, 0) with one point at the 0 o’clock position. Write a program that prompts the user to enter the radius of the bounding circle of a pentagon and displays the
coordinates of the five corner points on the pentagon. Here is a sample run:

Enter the radius of the bounding circle: 100
The coordinates of five points on the pentagon are
(95.1057, 30.9017)
(0.000132679, 100)
(-95.1056, 30.9019)
(-58.7788, -80.9015)
(58.7782, -80.902)

What we know , we know both the radius of the circle(user inputted) and the side of the pentagon from formula (double side = 2 * radius * Math.sin(Math.PI/5)) .We also know that one point is (0 .100) Also i know that the distance between 2 points is Math.sqrt(Math.pow(x1 - x2 ,2) - Math.pow(y1 -y2 ,2)) .
There might be other ways to solve it but this is my best bet trough i dont remember how to solve linear equations of the form x^2 + y^2 = - radius and radius ^2 = x^2 + (y - 100) ^ 2..

The solution i found is using the radius from the center to the point we want to find out and using the radius to the point we already know ( 0 .100) but i have to solve that damn equation first ...

Campbell Ritchie
Marshal
Posts: 56529
172
You notice there is imprecision that you have 0.000132679 as one of the coordinates rather than 0.0000000.

No, that is not the correct way to work out the coordinates. Remember one of the coordinates is rsinθ and the other is rcosθ. All you have to do is work out which direction is so θ = 0 and you're in action. I think 0° = right, and the angles are counted anticlockwise, but I am not sure. I posted about that a few weeks ago. Here. No, that was two weeks after I signed on. That was for clocks; it is slightly different for pentagons, but only slightly different.

Tiberius Marius
Ranch Hand
Posts: 115
3
Not sure i understand , the coordonates of the most extreme north point are already known (aka 0 , 100) .It's because the problem said that one point is at x = 0 and if x = 0 => y = radius( resolving y from the equation radius = Math.sqrt((x1 -x2) ^2 + (y1 -y2)^2) where the only unknown is one y . The problem is i don't know how to extract the rest of the coordonates . One way is to resolve the equations that result from radius from new point to center is Math.sqrt((x1 -x2) ^2 + (y1 -y2)^2) and distance from point ( 0.100) to the next point is knows => another equation <known quantity = Math.sqrt((x1 -x2) ^2 + (y1 -y2)^2) . But as i said i dont remember how to solve equations of the form x2 - y2 = <known quantity> and x2 + (y -100) = known quantity . I m sure there are other simpler ways of solving the problem but my math knowledge is very limited (i mean i dont know the formulas that would permit me to for example extract x and y from knowing the angles of a triangle .

Tony Docherty
Bartender
Posts: 3271
82
You might want to read up on basic trigonometry and in particular look at the cos and sin functions as Campbell has already suggested.
I would also advise computing this on paper before trying to code it.

Tiberius Marius
Ranch Hand
Posts: 115
3
thanks , will do

Campbell Ritchie
Marshal
Posts: 56529
172
If you are going to use that for a Swing display, you might do well to make some changes to the coordinate system.That sort of thing will move the origin of the coordinates to the middle of the display and change the y coordinates so larger number = ↑
Then use g2 for all drawing.

Tiberius Marius
Ranch Hand
Posts: 115
3
I dont know the graphical classes in Java , the exercise was theoretical(no need to draw anything) in the sense that the output is only the coordonates of the pentagon corners exactly as i posted in in the first post.