forum.boolean.name

forum.boolean.name (http://forum.boolean.name/index.php)
-   C++ (http://forum.boolean.name/forumdisplay.php?f=22)
-   -   Язык Си, помохите разобратся. (http://forum.boolean.name/showthread.php?t=12686)

CRASHER 18.06.2010 10:21

Язык Си, помохите разобратся.
 
Вот код
Код:

// Geometric Tools, LLC
// Copyright (c) 1998-2010
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
// http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
//
// File Version: 5.0.0 (2010/01/01)

#include "Wm5MathematicsPCH.h"
#include "Wm5IntrCircle2Circle2.h"

namespace Wm5
{
//----------------------------------------------------------------------------
template <typename Real>
IntrCircle2Circle2<Real>::IntrCircle2Circle2 (const Circle2<Real>& circle0,
    const Circle2<Real>& circle1)
    :
    mCircle0(&circle0),
    mCircle1(&circle1)
{
}
//----------------------------------------------------------------------------
template <typename Real>
const Circle2<Real>& IntrCircle2Circle2<Real>::GetCircle0 () const
{
    return *mCircle0;
}
//----------------------------------------------------------------------------
template <typename Real>
const Circle2<Real>& IntrCircle2Circle2<Real>::GetCircle1 () const
{
    return *mCircle1;
}
//----------------------------------------------------------------------------
template <typename Real>
bool IntrCircle2Circle2<Real>::Find ()
{
    // The two circles are |X-C0| = R0 and |X-C1| = R1.  Define U = C1 - C0
    // and V = Perp(U) where Perp(x,y) = (y,-x).  Note that Dot(U,V) = 0 and
    // |V|^2 = |U|^2.  The intersection points X can be written in the form
    // X = C0+s*U+t*V and X = C1+(s-1)*U+t*V.  Squaring the circle equations
    // and substituting these formulas into them yields
    //  R0^2 = (s^2 + t^2)*|U|^2
    //  R1^2 = ((s-1)^2 + t^2)*|U|^2.
    // Subtracting and solving for s yields
    //  s = ((R0^2-R1^2)/|U|^2 + 1)/2
    // Then replace in the first equation and solve for t^2
    //  t^2 = (R0^2/|U|^2) - s^2.
    // In order for there to be solutions, the right-hand side must be
    // nonnegative.  Some algebra leads to the condition for existence of
    // solutions,
    //  (|U|^2 - (R0+R1)^2)*(|U|^2 - (R0-R1)^2) <= 0.
    // This reduces to
    //  |R0-R1| <= |U| <= |R0+R1|.
    // If |U| = |R0-R1|, then the circles are side-by-side and just tangent.
    // If |U| = |R0+R1|, then the circles are nested and just tangent.
    // If |R0-R1| < |U| < |R0+R1|, then the two circles to intersect in two
    // points.

    Vector2<Real> U = mCircle1->Center - mCircle0->Center;
    Real USqrLen = U.SquaredLength();
    Real R0 = mCircle0->Radius, R1 = mCircle1->Radius;
    Real R0mR1 = R0 - R1;
    if (USqrLen < Math<Real>::ZERO_TOLERANCE
    &&  Math<Real>::FAbs(R0mR1) < Math<Real>::ZERO_TOLERANCE)
    {
        // Circles are essentially the same.
        mIntersectionType = IT_OTHER;
        mQuantity = 0;
        return true;
    }

    Real R0mR1Sqr = R0mR1*R0mR1;
    if (USqrLen < R0mR1Sqr)
    {
        mIntersectionType = IT_EMPTY;
        mQuantity = 0;
        return false;
    }

    Real R0pR1 = R0 + R1;
    Real R0pR1Sqr = R0pR1*R0pR1;
    if (USqrLen > R0pR1Sqr)
    {
        mIntersectionType = IT_EMPTY;
        mQuantity = 0;
        return false;
    }

    if (USqrLen < R0pR1Sqr)
    {
        if (R0mR1Sqr < USqrLen)
        {
            Real invUSqrLen = ((Real)1)/USqrLen;
            Real s = ((Real)0.5)*((R0*R0-R1*R1)*invUSqrLen+(Real)1);
            Vector2<Real> tmp = mCircle0->Center + s*U;

            // In theory, discr is nonnegative.  However, numerical round-off
            // errors can make it slightly negative.  Clamp it to zero.
            Real discr = R0*R0*invUSqrLen - s*s;
            if (discr < (Real)0)
            {
                discr = (Real)0;
            }
            Real t = Math<Real>::Sqrt(discr);
            Vector2<Real> V(U.Y(), -U.X());
            mQuantity = 2;
            mPoint[0] = tmp - t*V;
            mPoint[1] = tmp + t*V;
        }
        else
        {
            // |U| = |R0-R1|, circles are tangent.
            mQuantity = 1;
            mPoint[0] = mCircle0->Center + (R0/R0mR1)*U;
        }
    }
    else
    {
        // |U| = |R0+R1|, circles are tangent.
        mQuantity = 1;
        mPoint[0] = mCircle0->Center + (R0/R0pR1)*U;
    }

    mIntersectionType = IT_POINT;
    return true;
}
//----------------------------------------------------------------------------
template <typename Real>
int IntrCircle2Circle2<Real>::GetQuantity () const
{
    return mQuantity;
}
//----------------------------------------------------------------------------
template <typename Real>
const Vector2<Real>& IntrCircle2Circle2<Real>::GetPoint (int i) const
{
    return mPoint[i];
}
//----------------------------------------------------------------------------
template <typename Real>
const Circle2<Real>& IntrCircle2Circle2<Real>::GetIntersectionCircle () const
{
    return *mCircle0;
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// Explicit instantiation.
//----------------------------------------------------------------------------
template
class IntrCircle2Circle2<float>;

template
class IntrCircle2Circle2<double>;
//----------------------------------------------------------------------------
}

Код о пересечении 2-ух окружностей. Находит точки пересечения.
Помогите разобраться, если возможно и не сложно в блитце код напишите, тагды я сам 100 пудов разберусь. За язык Си садился только на 1 курсе в универе.

IGR 18.06.2010 10:42

Ответ: Язык Си, помохите разобратся.
 
хм.. Какая именно строчка непонятна ??

CRASHER 18.06.2010 11:29

Ответ: Язык Си, помохите разобратся.
 
IGR, мне координаты точек нужны. Не пойму где тут их определяют.

IGR 18.06.2010 12:36

Ответ: Язык Си, помохите разобратся.
 
CRASHER, ты уверен что сдесь пересечение 2х окружностей считается ??

пруф 0:
Цитата:

// Intersection of a the line P+t*D and the circle |X-C| = R. The line
// direction is unit length.
пруф 1:
Цитата:

bool intersects = Find(mLine->Origin, mLine->Direction,
mCircle->Center, mCircle->Radius, mQuantity, t);

Dream 18.06.2010 12:50

Ответ: Язык Си, помохите разобратся.
 
Цитата:

Vector2<Real>
какбы намекает

Mr_F_ 18.06.2010 14:46

Ответ: Язык Си, помохите разобратся.
 
Цитата:

#include "Wm5MathematicsPCH.h"
#include "Wm5IntrCircle2Circle2.h"
а тут мы даже хз что находится)
Цитата:

мне координаты точек нужны. Не пойму где тут их определяют.
как я понимаю после просчёта точек пересечения, тебе нужно взять кол-во, которое получилось через GetQuantity () а потом и сами точки через GetPoint (int i)

CRASHER 18.06.2010 15:44

Ответ: Язык Си, помохите разобратся.
 
Mr_F_, насчёт либ, это я могу выложить. Впринцепе все есть сдесь http://www.geometrictools.com/LibMat...ersection.html
Но вот исходя из кода можно сказать что в конце вычисления я получаю координаты?


Часовой пояс GMT +4, время: 07:31.

vBulletin® Version 3.6.5.
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Перевод: zCarot