开发者

best platform to draw curves and create JPEGs

i have an equation of a curve that i need to draw like:

((X^z)-1)/z = y

does anyone know how i c开发者_运维百科an draw this curve and save it as an image using python or .net?


A good library for 2d plots in Python is http://matplotlib.sourceforge.net/. The resulting plot can be saved straight from the plot dialog.


Here's an example of drawing your curve in .NET/C#:

References:

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

Drawing Code:

const int imgSize = 500;
var bmp = new Bitmap(imgSize, imgSize);
using (var g = Graphics.FromImage(bmp))
{
    g.SmoothingMode = SmoothingMode.HighQuality;
    var points = new Point[imgSize];
    const int z = 10;
    g.FillRectangle(Brushes.White, 0, 0, bmp.Width, bmp.Height);

    for (var x = 0; x < imgSize; x++)
    {
        var y = bmp.Height - (x^z-1)/z;
        points[x] = new Point(x, y);
    }

    g.DrawCurve(Pens.Black, points);
}

bmp.Save(@"C:\Users\your_name_here\Desktop\myCurve.png", ImageFormat.Png);

I made some assumption such as making Z a constant. Also the image size if fixed at 500 and the plotting only happens in the upper-right (positive/positive) location of the cartesian plane. But that's all stuff you can figure out. Note that Y needs to be adjusted since Windows plots 0,0 at the upper left of the screen: var y = bmp.Height - (x^z-1)/z;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜