//判断点和圆之间的关系。 点在圆上,圆外,圆内。
//
// Created by tim on 2021/6/14.
//
#include <iostream>
using namespace std;
#ifndef CHAPTER4_POINTER_H
#define CHAPTER4_POINTER_H
//点类,所谓点就是一个坐标。(x,y)
class Pointer {
private :
int m_X;
int m_Y;
public :
void setX(int x);
int getX();
void setY(int y);
int getY();
};
#endif //CHAPTER4_POINTER_H
//
// Created by tim on 2021/6/14.
//
#include "Pointer.h"
void Pointer::setX(int x) {
m_X = x;
}
int Pointer::getX() {
return m_X;
}
void Pointer::setY(int y) {
m_Y = y;
}
int Pointer::getY() {
return m_Y;
}
//
// Created by tim on 2021/6/14.
//
#include <iostream>
using namespace std;
#include "Pointer.h"
#ifndef CHAPTER4_CIRCLE_H
#define CHAPTER4_CIRCLE_H
//圆类,有一个圆心和半径构成
class Circle{
private:
int m_R;
Pointer m_Center;
public:
void setR(int r);
int getR();
void setCenter(Pointer cneter);
Pointer getCenter();
bool isInCircle(Pointer pointer);
};
#endif //CHAPTER4_CIRCLE_H
//
// Created by tim on 2021/6/14.
//
#include "Circle.h"
#include<math.h>
void Circle::setR(int r) {
m_R = r;
}
int Circle::getR() {
return m_R;
}
void Circle::setCenter(Pointer cneter) {
m_Center = cneter;
}
Pointer Circle::getCenter() {
return m_Center;
}
//判断该点是否在圆内,外,上等。 用(x,y)坐标差平方和 与半径平方做对比。
bool Circle::isInCircle(Pointer pointer) {
int distance = pow(this->getCenter().getX()-pointer.getX(),2) + pow(this->getCenter().getY()-pointer.getY(),2);
int rDistance = pow(this->getR(),2);
if (distance == rDistance){
cout << "点在圆上。";
}else if (distance > rDistance){
cout << "点在圆外";
}else{
cout << "点在圆内。";
}
}
#include <iostream>
using namespace std;
#include "Circle.h"
//判断点和圆之间的关系。 点在圆上,圆外,圆内。
int main() {
Circle circle;
//设定圆,圆心,半径。
Pointer center;
center.setX(10);//设定圆心x轴
center.setY(0);//设定圆心y轴
circle.setR(10);//设定圆的半径
circle.setCenter(center);
//设定点,
Pointer pointer;
pointer.setX(10);
pointer.setY(9);
circle.isInCircle(pointer);
return 0;
}