Exemplo n.º 1
0
//! Returns true if the current atom is covalently bonded to a given atom.
bool atom::is_neighbor(const atom& a) const
{
	assert(this != &a);
	const double r = 1.1 * (covalent_radius() + a.covalent_radius());
	return distance_sqr(coord, a.coord) < r * r;
}
Exemplo n.º 2
0
double distance(struct Point const a, struct Point const b)
{
    return sqrt(distance_sqr(a, b));
}
Exemplo n.º 3
0
bool atom::has_covalent_bond(const atom& a) const
{
	const float s = covalent_radius() + a.covalent_radius();
	return distance_sqr(coord, a.coord) < s * s;
}
Exemplo n.º 4
0
int insect(Circle c1,Circle c2)
{
    double d,a,b,c,p,q,r;
    double cos_value[2], sin_value[2];
    if (double_equals(c1.p.x, c2.p.x)&& double_equals(c1.p.y,c2.p.y)&& double_equals(c1.r, c2.r))
    {
        return 0;
    }
    d = distance(c1.p, c2.p);
    if (d > c1.r + c2.r||d < fabs(c1.r - c2.r))
    {
        return 0;
    }

    a = 2.0 * c1.r * (c1.p.x - c2.p.x);
    b = 2.0 * c1.r * (c1.p.y - c2.p.y);
    c = c2.r * c2.r - c1.r * c1.r- distance_sqr(c1.p,c2.p);
    p = a * a + b * b;
    q = -2.0 * a * c;
    if(p==0)return 0;
    if (double_equals(d,c1.r +c2.r)|| double_equals(d, fabs(c1.r - c2.r)))
    {
        cos_value[0] = -q / p / 2.0;
        sin_value[0] = sqrt(1 - cos_value[0] * cos_value[0]);

        I0->x = c1.r * cos_value[0] + c1.p.x;
        I0->y = c1.r * sin_value[0] + c1.p.y;

        if (!double_equals(distance_sqr(*I0, c2.p),c2.r * c2.r))
        {
            I0->y = c1.p.y - c1.r * sin_value[0];
        }
        return 1;
    }

    r = c * c - b * b;
    cos_value[0] = (sqrt(q * q - 4.0 * p * r) - q) / p / 2.0;
    cos_value[1] = (-sqrt(q * q - 4.0 * p * r) - q) / p / 2.0;
    sin_value[0] = sqrt(1 - cos_value[0] * cos_value[0]);
    sin_value[1] = sqrt(1 - cos_value[1] * cos_value[1]);

    I0->x = c1.r * cos_value[0] + c1.p.x;
    I1->x = c1.r * cos_value[1] + c1.p.x;
    I0->y = c1.r * sin_value[0] + c1.p.y;
    I1->y = c1.r * sin_value[1] + c1.p.y;

    if (!double_equals(distance_sqr(*I0, c2.p),c2.r * c2.r))
    {
        I0->y = c1.p.y - c1.r * sin_value[0];
    }
    if (!double_equals(distance_sqr(*I1, c2.p),c2.r * c2.r))
    {
        I1->y = c1.p.y - c1.r * sin_value[1];
    }
    if (double_equals(I0->y, I1->y)&& double_equals(I0->x, I1->x))
    {//改到这里了
        if (I0->y > 0)
        {
            I1->y = -I1->y;
        } else
        {
            I0->y = -I0->y;
        }
    }
    return 2;
}
Exemplo n.º 5
0
float point_line_distance_sqr(float4 point, line4 line)
{
	return distance_sqr(point, line.a + line.b * param_nearest_on_line(point, line));
}