Esempio n. 1
0
    static public Polynome2D MultiplyXYPolygones(Polynome1D xPolygon, Polynome1D yPolygon)
    {
        Polynome2D result = new Polynome2D();

        for (int x = 0; x < xPolygon.termCount; x++)
        {
            Term1D xTerm = xPolygon.terms[x];

            for (int y = 0; y < yPolygon.termCount; y++)
            {
                Term1D yTerm = yPolygon.terms[y];

                Term2D xyTerm = Term2D.MultiplyXYTerms(xTerm, yTerm);

                result += xyTerm;
            }

            result.AddXTerm(xTerm * yPolygon.constant);
        }

        for (int y = 0; y < yPolygon.termCount; y++)
        {
            Term1D yTerm = yPolygon.terms[y];

            result.AddYTerm(yTerm * xPolygon.constant);
        }

        result.m_k = xPolygon.constant * yPolygon.constant;

        return(result);
    }
Esempio n. 2
0
    public static Term2D operator *(Term2D a, Term2D b)
    {
        Term2D result = new Term2D();

        result.m_scalar = a.m_scalar * b.m_scalar;
        result.m_xPower = a.m_xPower + b.m_xPower;
        result.m_yPower = a.m_yPower + b.m_yPower;

        return(result);
    }
Esempio n. 3
0
    static public Term2D MultiplyXYTerms(Term1D xPolygon, Term1D yPolygon)
    {
        Term2D result = new Term2D();

        result.m_xPower = xPolygon.power;
        result.m_yPower = yPolygon.power;
        result.m_scalar = xPolygon.scalar * yPolygon.scalar;

        return(result);
    }
Esempio n. 4
0
    public void AddXYTerm(Term2D term)
    {
        for (int i = 0; i < m_xyTerms.Count; i++)
        {
            Term2D xyTerm = m_xyTerms[i];
            if ((xyTerm.xPower == term.xPower) && (xyTerm.yPower == term.yPower))
            {
                xyTerm      += term.scalar;
                m_xyTerms[i] = xyTerm;
                return;
            }
        }

        m_xyTerms.Add(term);
    }
Esempio n. 5
0
    static public Polynome2D operator +(Polynome2D polynome, Term2D term)
    {
        for (int i = 0; i < polynome.m_xyTerms.Count; i++)
        {
            Term2D xyTerm = polynome.m_xyTerms[i];
            if ((xyTerm.xPower == term.xPower) && (xyTerm.yPower == term.yPower))
            {
                xyTerm += term.scalar;
                polynome.m_xyTerms[i] = xyTerm;
                return(polynome);
            }
        }

        polynome.m_xyTerms.Add(term);
        return(polynome);
    }
Esempio n. 6
0
    public void Optimize()
    {
        Debug.Log("NOT IMPLEMENTED : Polynome2D.Optimize()");

        List <Term1D>  xTerms   = new List <Term1D>();
        List <Term1D>  yTerms   = new List <Term1D>();
        List <Term2D>  xyTerms  = new List <Term2D>();
        List <float>   xPowers  = new List <float>();
        List <float>   yPowers  = new List <float>();
        List <Vector2> xyPowers = new List <Vector2>();

        int   index;
        float xPower, yPower;

        foreach (Term2D xyTerm in m_xyTerms)
        {
            xPower = xyTerm.xPower;
            yPower = xyTerm.yPower;

            if ((xPower == 0) && (yPower == 0))
            {
                // Cas constante
                m_k += xyTerm.scalar;
            }
            else if (xPower == 0)
            {
                // convertir en y seul
                index = yPowers.IndexOf(yPower);
                if (index >= 0)
                {
                    // Présence de duplicatas, que l'on rassemble
                    Term1D presentYTerm = yTerms[index];
                    presentYTerm += xyTerm.scalar;
                    yTerms[index] = presentYTerm;
                }
                else
                {
                    yPowers.Add(yPower);
                    Term1D term = new Term1D(yPower, xyTerm.scalar);
                    yTerms.Add(term);
                }
            }
            else if (yPower == 0)
            {
                // convertir en x seul
                index = xPowers.IndexOf(xPower);
                if (index >= 0)
                {
                    // Présence de duplicatas, que l'on rassemble
                    Term1D presentXTerm = xTerms[index];
                    presentXTerm += xyTerm.scalar;
                    xTerms[index] = presentXTerm;
                }
                else
                {
                    xPowers.Add(xPower);
                    Term1D term = new Term1D(xPower, xyTerm.scalar);
                    xTerms.Add(term);
                }
            }
            else
            {
                Vector2 xyPower = new Vector2(xPower, yPower);

                index = xyPowers.IndexOf(xyPower);
                if (index >= 0)
                {
                    // Présence de duplicatas, que l'on rassemble
                    Term2D presentXTerm = xyTerms[index];
                    presentXTerm  += xyTerm.scalar;
                    xyTerms[index] = presentXTerm;
                }
                else
                {
                    xyPowers.Add(xyPower);
                    xyTerms.Add(xyTerm);
                }
            }
        }

        foreach (Term1D xTerm in m_xTerms)
        {
            xPower = xTerm.power;

            if (xPower == 0)
            {
                // Cas constante
                m_k += xTerm.scalar;
            }
            else
            {
                index = xPowers.IndexOf(xPower);
                if (index >= 0)
                {
                    // Présence de duplicatas, que l'on rassemble
                    Term1D presentXTerm = xTerms[index];
                    presentXTerm += xTerm.scalar;
                    xTerms[index] = presentXTerm;
                }
                else
                {
                    xPowers.Add(xPower);
                    xTerms.Add(xTerm);
                }
            }
        }

        foreach (Term1D yTerm in m_yTerms)
        {
            yPower = yTerm.power;

            if (yPower == 0)
            {
                // Cas constante
                m_k += yTerm.scalar;
            }
            else
            {
                index = yPowers.IndexOf(yPower);
                if (index >= 0)
                {
                    // Présence de duplicatas, que l'on rassemble
                    Term1D presentYTerm = yTerms[index];
                    presentYTerm += yTerm.scalar;
                    yTerms[index] = presentYTerm;
                }
                else
                {
                    yPowers.Add(yPower);
                    yTerms.Add(yTerm);
                }
            }
        }
    }
Esempio n. 7
0
 public static void Main(string[] args)
 {
     Term2D.Start(new ExampleGame());
 }
Esempio n. 8
0
 public XMLTerm2D(Term2D term)
 {
     m_scalar = term.scalar;
     m_xPower = term.xPower;
     m_yPower = term.yPower;
 }