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. css浮动的元素居中

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  2. 设计模式-生成者模式之c#代码

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  3. 前端之css笔记1

    1  css引入方式 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  4. jquery datables ajax分页后的点击事件无效是怎么回事

    异步请求数据后,动态向table中追加行,行点击事件失效 动态加入到DOM中的对象无法继承原有的事件,所以无效,举例: // $.ajax... ajax部分省略 var tr = "&qu ...

  5. 2018.08.21 NOIP模拟 unlock(模拟+找规律)

    unlock 描述 经济危机席卷全球,L国也收到冲击,大量人员失业. 然而,作为L国的风云人物,X找到了自己的新工作.从下周开始,X将成为一个酒店的助理锁匠,当然,他得先向部门领导展示他的开锁能力. ...

  6. 全球晶圆代工厂哪家强?2016年Top30名单

    1.台积电(TSMC) 总部:台湾 简介:世界上最大的独立半导体晶圆代工企业,与联华电子并称“晶圆双雄”. 主要客户:苹果,高通,联发科,华为海思 官网:http://www.tsmc.com/ 2. ...

  7. Caused by: Unable to load configuration. - action - file:/C:/apache-tomcat-7.0.70/webapps/Structs/WEB-INF/classes/struts.xml:7:72 at com.opensymphony.xwork2.config.ConfigurationManager.getConfigurati

    Unable to load configuration. - action - file:/C:/apache-tomcat-7.0.70/webapps/Structs/WEB-INF/class ...

  8. 20155218 2016-2017-2 《Java程序设计》第8周学习总结

    20155218 2016-2017-2 <Java程序设计>第8周学习总结 教材学习内容总结 java.util.logging包提供了日志功能相关类与接口,不必额外配置日志组件,就可以 ...

  9. Java菜鸟学习笔记()--面向对象篇(七):Wrapper Class包装类

    什么是包装类? 在Java里一切都是对象,除了Java中的基本数据类型(byte,short,int,long,char,float,double,boolean)不是面向对象的,这在实际使用时存在很 ...

  10. Java代码优化(一)

    前言 2016年3月修改,结合自己的工作和平时学习的体验重新谈一下为什么要进行代码优化.在修改之前,我的说法是这样的: 就像鲸鱼吃虾米一样,也许吃一个两个虾米对于鲸鱼来说作用不大,但是吃的虾米多了,鲸 ...