2 Replies - 457 Views - Last Post: 04 February 2011 - 07:14 PM Rate Topic: -----

#1 poncho4all  Icon User is offline

  • D.I.C Head!
  • member icon

Reputation: 123
  • View blog
  • Posts: 1,405
  • Joined: 15-July 09

Two lines (curves) that meet each other

Posted 04 February 2011 - 06:15 PM

Well I'm doing a graph drawing application to control electronic polarization of JFET.

The problem is that i have drawn the transference curve and i have another line that's going to help me find the Q point the problem is that i need to know when the 2 lines meet. I have no idea on how to do this, the drawing is made on a picture box, with an image
  public Bitmap GenerateGraph(int scale, int width, int height)
        {
            Bitmap image = new Bitmap(width, height);
            int midX = width / 2;
            int limY = height - 15;

            Graphics g = Graphics.FromImage(image);
            SolidBrush backgroundBrush = new SolidBrush(backgroundColor);
            SolidBrush axisBrush = new SolidBrush(axisColor);
            SolidBrush drawBrush = new SolidBrush(drawColor);
            SolidBrush drawQ = new SolidBrush(qColor);
            SolidBrush pointsBrush = new SolidBrush(pointsColor);

            Pen qPen = new Pen(qColor);
            Pen drawPen = new Pen(drawColor);
            Pen axisPen = new Pen(axisColor);
            Pen gridPen = new Pen(gridColor);
            Pen curvePen = new Pen(curveColor);
            Font axisFont = new Font(FontFamily.GenericSansSerif, axisFontSize);
            Font pointsFont = new Font(FontFamily.GenericSansSerif, pointsFontSize);
            //Limpiar Fondo  
            g.FillRectangle(backgroundBrush, 0, 0, width, height);

            //Dibujar Lineas
            if (drawAxes)
            {
                g.DrawLine(axisPen, 0, limY, width, limY);
                g.DrawLine(axisPen, midX, 0, midX, limY);

                //Dibujar Numeros
            curnumber = 0;
                float curX = midX;
                while (curX < width)
                {
                    if (curX != midX)
                    {
                        g.DrawLine(gridPen, curX, 0, curX, limY);
                    }

                    g.DrawLine(axisPen, curX, limY, curX, limY + 3);
                    g.DrawString(curnumber.ToString(), axisFont, axisBrush, curX - 3, limY + 5);
                    curX += scale;
                    curnumber++;
                }

                curnumber = 0;
                curX = midX;
                while (curX > 0)
                {
                    if (curX != midX)
                    {
                        g.DrawLine(gridPen, curX, 0, curX, limY);
                    }

                    g.DrawLine(axisPen, curX, limY, curX, limY + 3);
                    g.DrawString(curnumber.ToString(), axisFont, axisBrush, curX - 3, limY + 5);
                    curX -= scale;
                    curnumber--;
                }

                curnumber = 1;
                float curY = limY;
                while (curY > 0)
                {
                    if (curY != limY)
                    {
                        g.DrawLine(gridPen, 0, curY, width, curY);
                    }

                    g.DrawLine(axisPen, midX, curY, midX + 3, curY);
                    g.DrawString(curnumber.ToString(), axisFont, axisBrush, midX + 5, curY - (scale + 3));
                    curY -= scale;
                    curnumber++;
                }
            }

            //Graficar Transferencia
            double Vp;
            double Idss;
            double Id;
            double Vgs;
            float curXG = midX;
            float curYG = limY;
            //Polarizacion Fija
            double showId;
            double showVd;
            double Vg;
            double Vs = 0;
            double Vds;
            double Vgg;
            double Vdd;
            double Rd;
            //Autopolarizacion
            double aId;
            double aVd;
            double aVg;
            double aVs;
            double aVds;
            double aVdd;
            double aRd;
            double aRs;
            double aVgs;
            double aVrs;
            float p1;
            float p2;
           // double xAQ = Vp / 99;
            PointF[] aPuntos = new PointF[2];
            if (Double.TryParse(txtVp.Text, out Vp))
            {
                double x = Vp / 99;
                if ((Double.TryParse(txtIdss.Text, out Idss)) && (Idss > 0))
                {
                    if (Vp < 0)
                    {
                        Vgs = Vp;
                        txtTipo.Text = "N";
                        for (int i = 0; i < 100; i++)
                        {
                            Id = Idss * Math.Pow((1 - (Vgs / Vp)), 2);
                            IdPuntos[i] = new PointF((float)Vgs, (float)Id);
                            Id = Id * scale;
                            IdVgs[i] = new PointF((curXG + ((float)Vgs * scale)), (curYG - (float)Id));
                            Vgs = Vgs - x;
                        }
                    }

                    if (Vp > 0)
                    {
                        Vgs = Vp;
                        txtTipo.Text = "P";
                        for (int i = 0; i < 100; i++)
                        {
                            Id = Idss * Math.Pow((1 - (Vgs / Vp)), 2);
                            IdPuntos[i] = new PointF((float)Vgs, (float)Id);
                            Id = Id * scale;
                            IdVgs[i] = new PointF(curXG + ((float)Vgs * scale), curYG - (float)Id);
                            Vgs = Vgs - x;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Solo se aceptan numeros mayores a 0 en Idss");
                }
            }
            else
            {
                MessageBox.Show("Solo se aceptan numeros en Vp");
            }
            g.DrawCurve(curvePen, IdVgs);
            for (int i = 0; i < 100; i += 22)
            {
                double xP = IdPuntos[i].X;
                string sXP = String.Format("{0:0.00}", xP);
                double yP = IdPuntos[i].Y;
                string sYP = String.Format("{0:0.00}", yP);
                string punto = "( " + sXP +", "+ sYP +" )";
                g.DrawString(punto, pointsFont, pointsBrush, IdVgs[i]);
            }
            if (checkPolarizacionFija.Checked)
            {
                if (Double.TryParse(txtVp.Text, out Vp))
                {

                    if ((Double.TryParse(txtIdss.Text, out Idss)) && (Idss > 0))
                    {
                        if (Double.TryParse(txtVgg.Text, out Vgg))
                        {
                            Vgs = (-Vgg);
                            Vg = (Vgs + Vs);
                            showId = Idss * Math.Pow((1 - (Vgs / Vp)), 2);
                            if (double.TryParse(txtVdd.Text, out Vdd))
                            {
                                if (double.TryParse(txtRd.Text, out Rd))
                                {
                                    showVd = Vdd - (showId * Rd);
                                    Vds = showVd;
                                    txtId.Text = showId.ToString();
                                    txtVd.Text = showVd.ToString();
                                    txtVds.Text = Vds.ToString();
                                    txtVg.Text = Vg.ToString();
                                    txtVgs.Text = Vgs.ToString();
                                    txtVs.Text = Vs.ToString();
                                    string stringVgg = String.Format("{0:0.00}", (-Vgg));
                                    string stringId = String.Format("{0:0.00}", showId);
                                    txtQ.Text = "( " + stringVgg + ", " + stringId + " )";
                                    g.DrawLine(qPen, new PointF((curXG + ((float)Vgs * scale)), curYG),
                                        new PointF((curXG + ((float)(-Vgg) * scale)), (curYG - ((float)showId * scale))));
                                    g.DrawString("Q = ( " + stringVgg + ", " + stringId + " )", pointsFont,
                                        pointsBrush, new PointF((curXG + ((float)(-Vgg) * scale)), (curYG - ((float)showId * scale))));
                                }
                                else
                                {
                                    MessageBox.Show("Solo se aceptan Numeros");
                                }
                            }
                            else
                            {
                                MessageBox.Show("Solo se aceptan Numeros");
                            }
                        }
                        else
                        {
                            MessageBox.Show("Solo se aceptan Numeros");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Solo se aceptan Numeros");
                    }
                }
            }

            if (checkAutopolarizacion.Checked)
            {
               
                //Primer punto
                aPuntos[0] = new PointF(curXG, curYG);
                //Segundo Punto
                if (Double.TryParse(txtVp.Text, out Vp))
                {
                    if ((Double.TryParse(txtIdss.Text, out Idss)) && (Idss > 0))
                    {
                        if (Double.TryParse(txtRs.Text, out aRs))
                        {
                            aId = Idss / 2;
                            aVgs = ((-Idss) * aRs) / 2;
                            aPuntos[1] = new PointF(curXG + ((float)aVgs * scale), curYG - ((float)aId) * scale);
                            g.DrawCurve(qPen,aPuntos);
                        }
                    }
                }
                //punto Q
               
                //Calculos

            }

            return image;
        }

this is what it looks like the pic, what i need help with is, how to know when they meet. In witch point they have the same coordinates.

Any help with this would be appreciated

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Two lines (curves) that meet each other

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Two lines (curves) that meet each other

Posted 04 February 2011 - 07:11 PM

Have a look at Curve Intersection
Was This Post Helpful? 1
  • +
  • -

#3 poncho4all  Icon User is offline

  • D.I.C Head!
  • member icon

Reputation: 123
  • View blog
  • Posts: 1,405
  • Joined: 15-July 09

Re: Two lines (curves) that meet each other

Posted 04 February 2011 - 07:14 PM

I don't know why i didn't saw the math approach on this thank you sir for the remainder
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1