0

I need help in programming in c# (Microsoft Visual Studio C# 2010 Express) I need to be able to write a second degree function in a textbox and then when I click enter it draws the graph in a coordinatesystem for me. With other words I need to create a graph/parabola drawer for whatever second degree function I choose.

So far I have managed to make a first degree function drawer, I just have no idea how to make one for a second degree function.

Here are the codes for the first degree function drawer:

namespace Graph drawer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

    int K;
    int Ystart;
    int Yend;
    int Y1;

    protected override void OnPaint(PaintEventArgs e)
    {
        Graphics g = e.Graphics;
        Pen p=new Pen(Color.Black);
        g.DrawLine(p, 100, 250, 400, 250);
        g.DrawLine(p, 250, 100, 250, 400);
        g.DrawLine(p, 100, Ystart, 400, Yend);

    }

    private void btnDraw_Click(object sender, EventArgs e)
    {
        K = int.Parse(tbxFirstX.Text);
        int m = int.Parse(tbxM.Text);
        Ystart = 250 - 10 * m + K * 150;
        Yend = 250 - 10 * m - K * 150;
        Invalidate(); 
    }
Denis H
  • 11
  • 1
  • Last 4 tag seems unnecessary. Your question does not seems related neither `c++` nor specific `c#` version. – Soner Gönül May 28 '15 at 14:46
  • Which version of `c#` is this for and why is this tagged `c++`? – EdChum May 28 '15 at 14:46
  • Sorry for the tag. This is MIcrosoft visual studio C# 2010 express. – Denis H May 28 '15 at 14:50
  • Is your problem with the parsing or with the drawing? – Axel May 28 '15 at 15:03
  • I just dont know how to make the codes so it works for a second degree function as well. – Denis H May 28 '15 at 15:10
  • @DenisH You will have to draw the parabola point by point, dot by dot, iterating through possible abscissa values using small step (to get more or less good looking lines you will have to print at least few pixels per each x position). – Eugene Podskal May 28 '15 at 15:16
  • Yeah I had the same idea! I just don't know how to make the codes for it :( – Denis H May 28 '15 at 15:20
  • @DenisH To notify someone about your comment you should use [@username](http://meta.stackexchange.com/questions/43019/how-do-comment-replies-work) ping, otherwise they won't learn of your comment unless they manually check the post later. And what is the exact problem you are encountering? How to enumerate abscissa values(for loop that increases some `float x` by small value)? How to calculate ordinate from x(`y = a*x*x +b*x+c` and some position-on-form correction)? Or [how to draw single pixel](http://stackoverflow.com/questions/761003/draw-a-single-pixel-on-windows-forms)? Or something else? – Eugene Podskal May 28 '15 at 19:58
  • @DenisH Each of these tasks is quite simple on its own. That is just when you don't know where to start the problems may arise. Try to solve it once more step by step. If you encounter some problem - ask new question, just don't surrender too soon and make sure that the questions is up to the [requirements](http://meta.stackoverflow.com/questions/260648/stack-overflow-question-checklist). P.S.: Actually, per pixel painting through Graphics may be a bit inefficient, but as initial solution it will work well enough. – Eugene Podskal May 28 '15 at 20:03
  • @Eugene Podskal I'm kinda having problem with everything because I'm not really good at this, but mostly on how to draw the parabola point by point like you said earlier. – Denis H May 28 '15 at 20:12
  • That is why you should start from the beginning and end at the end: 1. enumerate X(abscissa) values 2. Get Y(ordinate) values from X values 3. Taking into account that you are painting not from 0,0 point but from some point at the form, add the appropiate corrections to get on-the-form points' coordinates. 4. Print each x-y pair as single point. If you know how to do each of them (and I have already given some advice in previous comments), then you will be left with relatively simple task of combining all of them into one working solution. – Eugene Podskal May 28 '15 at 20:24
  • @Eugene Podskal Well I have no idea how to do any of the them but I will try. Thanks for the info. – Denis H May 28 '15 at 20:56

0 Answers0