Example #1
0
        private void btnCalcula_Click(object sender, EventArgs eventArgs)
        {
            try
            {
                #region settando os campos
                coeficientes[0] = double.Parse(txtA.Text);
                coeficientes[1] = double.Parse(txtB.Text);
                coeficientes[2] = double.Parse(txtC.Text);
                coeficientes[3] = double.Parse(txtD.Text);
                coeficientes[4] = double.Parse(txtE.Text);
                coeficientes[5] = double.Parse(txtF.Text);

                funcmat.setA(coeficientes[0]);
                funcmat.setB(coeficientes[1]);
                funcmat.setC(coeficientes[2]);
                funcmat.setD(coeficientes[3]);
                funcmat.setE(coeficientes[4]);
                funcmat.setF(coeficientes[5]);

                funcmat.setAL(coeficientes[0]);
                funcmat.setBL(coeficientes[1]);
                funcmat.setCL(coeficientes[2]);
                funcmat.setDL(coeficientes[3]);
                funcmat.setEL(coeficientes[4]);
                #endregion

                // Mostrando Grafico ANTES DE ROTACIONAR/TRANSLADAR
                lblEquacaoAtual.Text = printEqAtual(coeficientes);
                ConicaGraph conica = new ConicaGraph(coeficientes, "Equação Inicial");
                conica.Show();
            }
            catch (System.FormatException a)
            {
                MessageBox.Show("Erro ao processar os campos!\nMais detalhes: " + a);
            }

            //Verifica se os termos lineares são 0, se for, pula para a rotação
            if (funcmat.getD() == 0 && funcmat.getE() == 0)
            {
                // Vai direto pra rotação SE TIVER O TERMO QUADRÁTICO MISTO
                if (funcmat.getB() == 0)
                {
                    //Não da pra fazer rotação também, a equação já está pronta
                }
                else
                {
                    matrizG2 = funcmat.gerarEquacaoG2(coeficientes[0], coeficientes[1], coeficientes[2], coeficientes[3], coeficientes[4], coeficientes[5]);
                    if (this.rotacao(false))
                    {
                        matrizG3 = funcmat.gerarEquacaoG2(funcmat.getAL(), (double)0, funcmat.getCL(), funcmat.getDL(), funcmat.getEL(), funcmat.getF());
                        lblEquacaoReduzida.Text = funcmat.mostraNovaEquacao2();
                    }
                    else
                    {
                        // Não realizou a rotação, então não elimina o termo quadrático misto
                        matrizG3 = funcmat.gerarEquacaoG2(funcmat.getAL(), funcmat.getB(), funcmat.getCL(), funcmat.getDL(), funcmat.getEL(), funcmat.getF());
                        lblEquacaoReduzida.Text = funcmat.mostraNovaEquacao2();
                    }
                }
            }
            else
            {
                // Fazer translação e rotação
                if (this.translacao())
                {
                    // Conseguiu fazer a translação
                    lblEquacaoReduzida.Text = funcmat.mostraNovaEquacao();
                    if (funcmat.getB() != 0) // Se não tiver termo quadrático misto não precisa fazer rotação
                    {
                        this.rotacao(true);  // True porque a translação deu certo
                    }
                }
                else
                {
                    MessageBox.Show("Não foi possível realizar a translação e remover os termos lineares!\nO sistema linear encontrado para achar os valores de H e K é incompatível ou tem infinitas soluções!\nIniciando rotação...", "Erro translação", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    // Não conseguiu fazer a translação
                    if (funcmat.getB() != 0) // Se não tiver termo quadrático misto não precisa fazer rotação
                    {
                        if (this.rotacao(false))
                        {
                            funcmat.setBL(0);
                            matrizG3 = funcmat.gerarEquacaoG2(funcmat.getAL(), funcmat.getBL(), funcmat.getCL(), funcmat.getDL(), funcmat.getEL(), funcmat.getF());
                            lblEquacaoReduzida.Text = funcmat.mostraNovaEquacao2();

                            // Atualizando os coeficientes
                            coeficientes[0] = funcmat.getAL();
                            coeficientes[1] = funcmat.getBL();
                            coeficientes[2] = funcmat.getCL();
                            coeficientes[3] = funcmat.getDL();
                            coeficientes[4] = funcmat.getEL();
                            coeficientes[5] = funcmat.getF();

                            if (this.translacao())
                            {
                                lblEquacaoReduzida.Text = funcmat.mostraNovaEquacao();
                            }
                            else
                            {
                                // Não conseguiu fazer a translação
                                MessageBox.Show("Não foi possível realizar a translação após a rotação");
                            }
                        }
                        else
                        {
                            // Não realizou a rotação, então não elimina o termo quadrático misto
                            matrizG3 = funcmat.gerarEquacaoG2(funcmat.getAL(), funcmat.getB(), funcmat.getCL(), funcmat.getDL(), funcmat.getEL(), funcmat.getF());
                            lblEquacaoReduzida.Text = funcmat.mostraNovaEquacao2();
                        }
                    }
                }
                lblEquacaoReduzida.Text = funcmat.mostraNovaEquacao();
            }
            // colcoa as informacoes para serem processadas pelo form

            // Atualizando os coeficientes
            coeficientes[0] = funcmat.getAL();
            coeficientes[1] = funcmat.getBL();
            coeficientes[2] = funcmat.getCL();
            coeficientes[3] = funcmat.getDL();
            coeficientes[4] = funcmat.getEL();
            coeficientes[5] = funcmat.getF();
            InfoConica info = new InfoConica(coeficientes);
            info.Show();

            // Mostrando Grafico DEPOIS DE ROTACIONAR/TRANSLADAR
            lblEquacaoAtual.Text = printEqAtual(coeficientes);
            ConicaGraph conica2 = new ConicaGraph(coeficientes, "Equação Simplificada");
            conica2.Show();
        }