Plot.cs

using Microsoft.ClearScript;
using Microsoft.ClearScript.V8;
using Microsoft.Win32;
using System;
using System.IO;
using System.IO.Packaging;
using System.Printing;
using System.Windows;
using System.Windows.Media;
using System.Windows.Xps.Packaging; namespace Plot
{
class Plot
{
[STAThread]
static void Main(string[] args)
{
Console.Title = "Plot";
var openFileDialog = new OpenFileDialog()
{
Filter = "JavaScript|*.js"
};
while (openFileDialog.ShowDialog() != true) ;
Console.WriteLine("Entry: ");
Console.WriteLine("Start: ");
Console.WriteLine("End: ");
Console.WriteLine("Step: ");
Console.CursorTop = ;
Console.CursorLeft = ;
var entry = Console.ReadLine();
Console.CursorLeft = ;
var start = double.Parse(Console.ReadLine());
Console.CursorLeft = ;
var end = double.Parse(Console.ReadLine());
Console.CursorLeft = ;
var step = double.Parse(Console.ReadLine());
var fileStream = new FileStream(openFileDialog.FileName, FileMode.Open);
var streamReader = new StreamReader(fileStream);
var v8ScriptEngine = new V8ScriptEngine();
var v8Script = v8ScriptEngine.Compile(streamReader.ReadToEnd());
v8ScriptEngine.Execute(v8Script);
while (v8ScriptEngine.Script[entry] is Undefined)
{
MessageBox.Show(entry + " not exist!");
Console.CursorTop = ;
Console.CursorLeft = ;
for (int i = ; i < entry.Length; i++)
{
Console.Write((char));
}
Console.CursorLeft = ;
entry = Console.ReadLine();
Console.CursorTop = ;
}
var saveFileDialog = new SaveFileDialog()
{
Filter = "XPS 文档|*.xps"
};
while (saveFileDialog.ShowDialog() != true) ;
var package = Package.Open(saveFileDialog.FileName, FileMode.Create);
var xpsDocument = new XpsDocument(package);
var xpsDocumentWriter = XpsDocument.CreateXpsDocumentWriter(xpsDocument);
int count = (int)((end - start) / step) + ;
var abscissa = new double[count];
var ordinate = new double[count];
for (int i = ; i < count; i++)
{
abscissa[i] = start + step * i;
ordinate[i] = v8ScriptEngine.Script[entry](abscissa[i]);
}
double semiWidth = Math.Ceiling(Math.Max(Math.Abs(start), Math.Abs(end)));
double width = semiWidth * ;
double height = semiWidth * ;
double thickness = 0.01;
double phi = 0.5 * Math.Sqrt() + 0.5;
var drawingVisual = new DrawingVisual();
var drawingContext = drawingVisual.RenderOpen();
drawingContext.PushTransform(new TranslateTransform(width / , height / ));
drawingContext.PushTransform(new ScaleTransform(, -));
var orangeRedPen = new Pen(Brushes.OrangeRed, thickness);
var thickOrangeRedPen = new Pen(Brushes.OrangeRed, thickness * phi);
var thinOrangeRedPen = new Pen(Brushes.OrangeRed, thickness / phi);
drawingContext.DrawLine(thickOrangeRedPen, new Point(, semiWidth), new Point(, -semiWidth));
drawingContext.DrawLine(thickOrangeRedPen, new Point(semiWidth, ), new Point(-semiWidth, ));
var thickBluePen = new Pen(Brushes.Blue, thickness * phi);
for (int i = ; i < (int)semiWidth * ; i++)
{
var pen = (Pen)null;
if (i % != )
{
pen = thinOrangeRedPen;
}
else
{
pen = orangeRedPen;
}
drawingContext.DrawLine(pen, new Point(0.1 * i, semiWidth), new Point(0.1 * i, -semiWidth));
drawingContext.DrawLine(pen, new Point(semiWidth, 0.1 * i), new Point(-semiWidth, 0.1 * i));
drawingContext.DrawLine(pen, new Point(-0.1 * i, semiWidth), new Point(-0.1 * i, -semiWidth));
drawingContext.DrawLine(pen, new Point(semiWidth, -0.1 * i), new Point(-semiWidth, -0.1 * i));
}
for (int i = ; i < count - ; i++)
{
if (!double.IsNaN(ordinate[i]) && !double.IsNaN(ordinate[i + ]))
{
drawingContext.DrawLine(thickBluePen, new Point(abscissa[i], ordinate[i]), new Point(abscissa[i + ], ordinate[i + ]));
}
}
drawingContext.Close();
var printTicket = new PrintTicket()
{
PageMediaSize = new PageMediaSize(width, height)
};
xpsDocumentWriter.Write(drawingVisual, printTicket);
xpsDocument.Close();
package.Close();
}
}
}

A Tool To Plot Mathematical Function的更多相关文章

  1. R语言画全基因组关联分析中的曼哈顿图(manhattan plot)

    1.在linux中安装好R 2.准备好画曼哈顿图的R脚本即manhattan.r,manhattan.r内容如下: #!/usr/bin/Rscript #example : Rscript plot ...

  2. SP Flash Tool New Version v5.1352.01

    Friends, Sp Tool updated to new version with whole new revamped interface New SP Flash Tool 3.1352.0 ...

  3. Octave中plot函数的用法

    octave:14> help plot'plot' is a function from the file C:\Octave\Octave3.6.4_gcc4.6.2\share\octav ...

  4. 基于MATLAB的多项式数据拟合方法研究-毕业论文

    摘要:本论文先介绍了多项式数据拟合的相关背景,以及对整个课题做了一个完整的认识.接下来对拟合模型,多项式数学原理进行了详细的讲解,通过对文献的阅读以及自己的知识积累对原理有了一个系统的认识.介绍多项式 ...

  5. LaTeX绘图宏包 Pgfplots package

    Pgfplots package The pgfplots package is a powerful tool, based on tikz, dedicated to create scienti ...

  6. Machine Learning and Data Mining(机器学习与数据挖掘)

    Problems[show] Classification Clustering Regression Anomaly detection Association rules Reinforcemen ...

  7. [C2P3] Andrew Ng - Machine Learning

    ##Advice for Applying Machine Learning Applying machine learning in practice is not always straightf ...

  8. Exercises for IN1900

    Exercises for IN1900October 14, 2019PrefaceThis document contains a number of programming exercises ...

  9. Maple拥有优秀的符号计算和数值计算能力

    https://www.maplesoft.com/products/maple/ Maple高级应用和经典实例: https://wenku.baidu.com/view/f246962107221 ...

随机推荐

  1. Apache Cordova vs Adobe PhoneGap: the differences and which one to use

    http://www.makehybridapps.com/2014/06/09/cordova-vs-phonegap-the-differences-and-which-one-to-use/

  2. css水波动画效果

    代码来源:http://www.jq22.com/code1526 HTML: <div class="waves"></div> css: html, b ...

  3. bzr: ERROR: These branches have diverged. Use the missing command to see how.

    这个错误是在提交之后执行bzr pull时出现的,先uncommit,再pull就可以了.

  4. ubuntu下设置DNS服务器

    当网卡通过DHCP获取IP地址时,DHCP会根据DHCP服务器配置,自动给系统分配DNS服务器地址,此时执行 ping www.baidu.com 动作,会将百度的域名在本地转换成ip地址,然后走路由 ...

  5. redis缓存设置和读取

    一/写入 <?php $redis = new Redis(); //实例化redis $redis->pconnect('); $redis->,'huahua'); //设置变量 ...

  6. url传递数据

    一.post传递数据 $ci = curl_init($url); curl_setopt($ci, CURLOPT_HEADER, 0); curl_setopt($ci, CURLOPT_RETU ...

  7. bootstrap中让图片自适应不同的分辨率的方法

    boostrap中加上这个样式class="img-responsive"图片就可以自适应,手机端同样适用 详细介绍请查看全文:https://cnblogs.com/qianzf ...

  8. 2018.09.07 Amount of degrees(数位dp)

    描述 求给定区间[X,Y]中满足下列条件的整数个数:这个数恰好等于K个互不相等的B的整数次幂之和. 例如,设X=15,Y=20,K=2,B=2,则有且仅有下列三个数满足题意: 17 = 24+20, ...

  9. Django介绍(3)

    https://www.cnblogs.com/yuanchenqi/articles/5786089.html

  10. nexus 私服跑一跑流程

    尝试建立新项目上传,分享 D:\dev\workspace\helloworld>tree /F 卷 DATAPART 的文件夹 PATH 列表 卷序列号为 2C22-0A1A D:. │ po ...