get equivalent polar coordinates

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef _POINTCLASS_H
#define	_POINTCLASS_H

#define	_POINTCLASSS_H


#include <iostream>

using namespace std;
class Point {
private:
    double x;
    double y;
public:
    Point();
    Point(double anx, double ay);
    bool Equals(Point& otherPt);
    double GetX() const;
    double GetY() const;
    void SetX(double newX);
    void SetY(double newY);

    //void AddOffsetPoint(const Point& other);
    void Print(ostream& out) const;
    friend ostream& operator<<(ostream& out, const Point& pt);

    double Radius() const;
    double Theta() const;
};

inline double Point::GetX() const { return x; }
inline double Point::GetY() const { return y; }
inline ostream& operator<<(ostream& out, const Point & pt) {
    pt.Print(out);
    return out;
}

my header

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "PointClass.h"

#include <math.h>

Point::Point() { x = y = 0.0 ; }

Point::Point(double anx, double ay) { x = anx; y = ay; }

bool Point::Equals(Point& otherPt) {
    return (this->x==otherPt.x) && (this->y==otherPt.y);
}

void Point::SetX(double newX) { x = newX; }
void Point::SetY(double newY) { y = newY; }



void Point::Print(ostream& out) const {
    out << "[" << x << ", " << y << "]";
}


don't know how to start to define Radius() and Theta()
can any body give some suggestion and sample coding for me?
If you just want to know how to calculate the radius and angle theta, it's pretty straightforward.

The radius can be found using Pythagoras' theorem
sqrt(x*x + y*y);

Theta can be determined using the function atan2()
http://www.cplusplus.com/reference/cmath/atan2/
@chervil.

i already did that and thanks you for your patiently teaching me

polar coordinates are written in the from (r, theta) were r is the radius and theta is the anti-clockwise angle for the positive x-axis.

here is this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
double Point::Radius() const{
    return sqrt( x*x + y*y );
}

double Point::Theta() const{
    double PI = 3.142;
    double result = 0.00;
    result = atan2(y,x) * 180 / PI;
}

void Point::polarCoordinate(double radius , double theta ){
    radius = Radius();
    theta  = Theta();
}


so currently did i correct?

so how should i actually create few points whose polar coordinates and invoke my new method already , my head confusing due to i done 2 algorithm multiplication today . sorry for it
Last edited on
Function double Point::Theta() should return a value.

I'm not sure what you want function Point::polarCoordinate to do? If you want to return the values of radius and theta, then pass them by reference.

Or are you trying to alter an existing point using the supplied values of radius and theta?
@chervil

i did not paste correctly
1
2
3
4
5
6
double Point::Theta() const{
    double PI = 3.142;
    double result = 0.00;
    result = atan2(y,x) * 180 / PI;
    return result;
}

because i don't really understand what is polar coordinate count out

here is the example link :
http://www.algebra.com/algebra/homework/Trigonometry-basics/Trigonometry-basics.faq.question.43941.html

1
2
3
4
void Point::polarCoordinate(double &radius , double &theta ){
    radius = Radius();
    theta  = Theta();
}


Last edited on
can someone help me out
I had a look yesterday, I thought your code looked ok.
Can you please explain what is the exact question you have.
Add code to the PointClassDriver program to create a few points whose polar coordinates you would know and which then invokes your new method

not really know how to make it to showing out .
That's just asking you to try some data to test that your code works correctly. In function main() add a few points, for example
1
2
3
    Point a(5,5);
    Point b(1, sqrt(3.0));
    Point c(3, -4);

Then call the polarCoordinate() method and output the resulting values of radius and theta.

The expected results for my suggested data is
a will have radius = 7.07106781186548 and theta = 45
b should have radius = 2 and theta = 60
and c has radius = 5 and theta = -53.130102354156

Of course the choice of data is up to you, these are just examples.
@chervil

thanks for your support !
it's totally working fine
next time have problem can i inbox u again?
your help is well understanding and u are patiently to teach me.

THUMBS UP FOR GOOD SENIOR LIKEYOU
Glad its working out.

If you need help in the future, just post a question in this forum, I don't accept messages, simply because I forget to read them until weeks later.
Topic archived. No new replies allowed.