Jackson Daniels

Greenhorn

Posts: 21

posted 1 year ago

Hello! I was assigned to use a PolarPnt class that implements Point (interface). We have to complete methods like returning the x coordinate. I was wondering how to go about this? How do I convert from a polar point to cartesian point in java and then output just the x coordinate? I am assuming you call the angle and the find the cos of theta and then multiply by the hypotenuse? I just have no idea how to write this in java.

posted 1 year ago

To find the cosine of an angle in Java you do this:

Bear in mind that the angle has to be in radians, so if you have an angle in degrees then there's another method in the Math class to convert degrees to radians. You seem to have the required calculations under control (I think... haven't reviewed the trigonomety in detail) so that's probably what you're missing. If there's anything else, then we're here to answer questions.

Bear in mind that the angle has to be in radians, so if you have an angle in degrees then there's another method in the Math class to convert degrees to radians. You seem to have the required calculations under control (I think... haven't reviewed the trigonomety in detail) so that's probably what you're missing. If there's anything else, then we're here to answer questions.

Jackson Daniels

Greenhorn

Posts: 21

posted 1 year ago

There's two parts to that, right? The first part is that you have to create a new CartesianPoint object (is that the name of the class?) so you'd have to use one of the class's constructors. The second part is that you have to set the state of that object -- that's the internal variables -- so that it represents a point rotated 90 degrees from the other point. (Clockwise or anticlockwise? Hopefully your assignment specifies.)

The second part requires some trigonometry like what you already did. You might pass the results from that part into the CartesianPoint constructor, or you might have to create that object first and then call some method to set its state. All depends on what you've got so far.

Does that help?

The second part requires some trigonometry like what you already did. You might pass the results from that part into the CartesianPoint constructor, or you might have to create that object first and then call some method to set its state. All depends on what you've got so far.

Does that help?