• Create Account

# Maple Wan

Member Since 04 Sep 2013
Offline Last Active May 16 2016 09:19 PM

### #5093174Strategy pattern.... am I on the right track?

Posted by on 10 September 2013 - 07:35 PM

Where is your override keyword? To realize Polymorphism, you have to implement 3 conditions:

1. Contains inheritance.(Interface or base class)

2. Contains override(use abstract/override or virtual/override or realize the interface method)

3. Mutiple base class objects which point to a derived class reference.

You should use override keyword in your derived class to replace the behavior of base class. Otherwise you should use new keyword to prevent derived class to replace the method of base class.

### #5093170rotating objects in a double orbit

Posted by on 10 September 2013 - 07:26 PM

Well, you should know the concepts of relative coordinate system and world coordinate system. Your triangles should save your relative point list and the center point. Then update the relative point list when rotate for some radius and redraw it. Give some simple code:

```#define PI 3.1415926535

typedef struct
{
double x, y;
} POINT, *LPPOINT;
typedef class Triangle
{
private:
POINT pointList[3];
POINT centerPoint;
public:
Triangle() { };  // Constructor
~Triangle() { };  // Destructor
BOOL Draw();    // Realize your Draw method
BOOL Rotate(double theta);    // Rotate method
} TRIANGLE, *LPTRIANGLE;

BOOL TRIANGLE::Rotate(double theta)
{
double cosVal, sinVal;
for (int i = 0; i < 3; i++)
{
cosVal = cos(theta * PI / 180);
sinVal = sin(theta * PI / 180);
// Compute the relative coordinate after rotate
this->pointList[i].x = this->pointList[i].x * cosVal - this->pointList[i].y * sinVal;
this->pointList[i].y = this->pointList[i].x * sinVal + this->pointList[i].y * cosVal;
}
return this->Draw();

BOOL TRIANGLE::Draw()
{
// In your draw method, you should change your relative coordinate to world coordinate.
}
```

PARTNERS