Извините, ничего не найдено.

Не расстраивайся! Лучше выпей чайку!
Регистрация
Справка
Календарь

Вернуться   forum.boolean.name > Программирование игр для компьютеров > C++

Ответ
 
Опции темы
Старый 18.06.2010, 10:21   #1
CRASHER
Разработчик
 
Регистрация: 08.03.2007
Сообщений: 530
Написано 31 полезных сообщений
(для 36 пользователей)
Язык Си, помохите разобратся.

Вот код
// 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 курсе в универе.

Последний раз редактировалось CRASHER, 18.06.2010 в 15:46.
(Offline)
 
Ответить с цитированием
Старый 18.06.2010, 10:42   #2
IGR
Blitz's Shame !!
 
Регистрация: 31.03.2007
Сообщений: 3,639
Написано 832 полезных сообщений
(для 2,013 пользователей)
Ответ: Язык Си, помохите разобратся.

хм.. Какая именно строчка непонятна ??
(Offline)
 
Ответить с цитированием
Старый 18.06.2010, 11:29   #3
CRASHER
Разработчик
 
Регистрация: 08.03.2007
Сообщений: 530
Написано 31 полезных сообщений
(для 36 пользователей)
Ответ: Язык Си, помохите разобратся.

IGR, мне координаты точек нужны. Не пойму где тут их определяют.
(Offline)
 
Ответить с цитированием
Старый 18.06.2010, 12:36   #4
IGR
Blitz's Shame !!
 
Регистрация: 31.03.2007
Сообщений: 3,639
Написано 832 полезных сообщений
(для 2,013 пользователей)
Ответ: Язык Си, помохите разобратся.

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);
(Offline)
 
Ответить с цитированием
Старый 18.06.2010, 12:50   #5
Dream
быдло
 
Регистрация: 05.08.2007
Сообщений: 1,435
Написано 614 полезных сообщений
(для 1,489 пользователей)
Ответ: Язык Си, помохите разобратся.

Vector2<Real>
какбы намекает
(Offline)
 
Ответить с цитированием
Старый 18.06.2010, 14:46   #6
Mr_F_
Терабайт исходников
 
Аватар для Mr_F_
 
Регистрация: 13.09.2008
Сообщений: 3,947
Написано 2,189 полезных сообщений
(для 6,051 пользователей)
Ответ: Язык Си, помохите разобратся.

#include "Wm5MathematicsPCH.h"
#include "Wm5IntrCircle2Circle2.h"
а тут мы даже хз что находится)
мне координаты точек нужны. Не пойму где тут их определяют.
как я понимаю после просчёта точек пересечения, тебе нужно взять кол-во, которое получилось через GetQuantity () а потом и сами точки через GetPoint (int i)
__________________
бложик | geom.io | твиттер | faded | демо 1 2 | роботы | лайтмаппер
(Offline)
 
Ответить с цитированием
Старый 18.06.2010, 15:44   #7
CRASHER
Разработчик
 
Регистрация: 08.03.2007
Сообщений: 530
Написано 31 полезных сообщений
(для 36 пользователей)
Ответ: Язык Си, помохите разобратся.

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


Опции темы

Ваши права в разделе
Вы не можете создавать темы
Вы не можете отвечать на сообщения
Вы не можете прикреплять файлы
Вы не можете редактировать сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.


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


vBulletin® Version 3.6.5.
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Перевод: zCarot
Style crйe par Allan - vBulletin-Ressources.com