数据结构 图形

来源:百度知道 编辑:UC知道 时间:2024/05/14 08:31:01
请高手写一个数据结构的伪代码: 判断一个顶点是否在一个圆上
更正一下题目: 是和图论算法中的拓扑排序有关的, 判断一个顶点(vertex)是否在一个圈上(cycle)

struct point
{
int x;
int y;
};
struct circle
{
int centerX;//圆心x
int centerY;//y
int r;//半径
};

//根据 (x-centerX)^2 + (y-centerY)^2 = r^2 圆方程

例如 struct point p;
初始化p...
struct circle c;
初始化c...
// 假设pow是乘方函数. pow(x,2)即 x^2
if(pow(p.x-c.centerX , 2)+pow(p.y-c.centerY ,2) == pow(c.r,2))
return TRUE;
else
return FALSE;