bool CMy2DObjectB11::IsInside(double x, double y) {
    double new_x, new_y, tmp, new_x1, new_y1, new_x2, new_y2;
    // перенос
    x -= this->m_center.GetX();
    y -= this->m_center.GetY();

    // поворот
    new_x1 = x * cos(this->m_dAngle) - y * sin(this->m_dAngle);
    new_y1 = x * sin(this->m_dAngle) + y * cos(this->m_dAngle);

    // поворот на 90
    new_x2 = new_x1 * cos(M_PI / 2) - new_y1 * sin(M_PI / 2);
    new_y2 = new_x1 * sin(M_PI / 2) + new_y1 * cos(M_PI / 2);

    // смена осей координат
    tmp = new_x2;
    new_x = new_y2;
    new_y = tmp;


    // проверка на выход за границы фигуры по оси X
    if (new_x > (this->A / 2) || new_x < -(this->A / 2)) {
        return false;
    }
    // проверка на выход за границы фигуры по оси Y
    if (new_y >(this->A / 2) || new_y < -(this->A / 2)) {
        return false;
    }

    // проверка на выход за прямоугольник A1
    if ((new_x > this->A / 2 - this->A1) &&
        (-this->A1 / 2 < new_y) && (new_y < this->A1 / 2)) {
        return false;
    }

    // проверка на выход за треугольник A2
    bool isInA2Square =
        (-this->A / 2 <= new_x && new_x <= -this->A / 2 + this->A2) &&
        (this->A / 2 - this->A2 <= new_y && new_y <= this->A / 2);
    if (isInA2Square) {
        bool isInInnerA2Triangle = IsInTriangle(
            CMy2DPoint(-this->A / 2 + this->A2, this->A / 2),
            CMy2DPoint(-this->A / 2 + this->A2, this->A / 2 - this->A2),
            CMy2DPoint(-this->A / 2, this->A / 2 - this->A2),
            CMy2DPoint(new_x, new_y));
        if (!isInInnerA2Triangle) {
            return false;
        }
    }

    // проверка на выход за треугольник A3
    bool isInA3Square =
        (-this->A / 2 <= new_x && new_x <= -this->A / 2 + this->A3) &&
        (-this->A / 2 <= new_y && new_y <= -this->A / 2 + this->A3);
    if (isInA3Square) {
        bool isInnerA3Triangle = IsInTriangle(
            CMy2DPoint(-this->A / 2, -this->A / 2 + this->A3),
            CMy2DPoint(-this->A / 2 + this->A3, -this->A / 2 + this->A3),
            CMy2DPoint(-this->A / 2 + this->A3, -this->A / 2),
            CMy2DPoint(new_x, new_y));
        if (!isInnerA3Triangle) {
            return false;
        }
    }

    // все проверки прошли успешно, точка внутри фигуры.
    return true;
}
Пример #2
0
const CMy2DPoint CMy2DPoint::operator+(const CMy2DPoint & b){
	return CMy2DPoint((*this).m_dx + b.m_dx, (*this).m_dy + b.m_dy);
}
void CMy2DObjectB11::Move(double dX, double dY, double dAngle) {
    this->Move(CMy2DPoint(dX, dY), dAngle);
};
Пример #4
0
const CMy2DPoint operator/(const CMy2DPoint & a, const CMy2DPoint & b){
	return CMy2DPoint(a.m_dx / b.m_dx, a.m_dy / b.m_dy);
}
Пример #5
0
const CMy2DPoint operator/(const CMy2DPoint & a, const double & b){
	return CMy2DPoint(a.m_dx / b, a.m_dy / b);
}
Пример #6
0
const CMy2DPoint operator*(const CMy2DPoint & a, const double & b){
	return CMy2DPoint(a.m_dx * b, a.m_dy * b);
}
Пример #7
0
const CMy2DPoint operator*(const double & a, const CMy2DPoint & b){
	return CMy2DPoint(a * b.m_dx, a * b.m_dy);
}
Пример #8
0
const CMy2DPoint CMy2DPoint::operator-(const CMy2DPoint & b){
	return CMy2DPoint((*this).m_dx - b.m_dx, (*this).m_dy - b.m_dy);
}