A Tool To Plot Mathematical Function
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的更多相关文章
- R语言画全基因组关联分析中的曼哈顿图(manhattan plot)
1.在linux中安装好R 2.准备好画曼哈顿图的R脚本即manhattan.r,manhattan.r内容如下: #!/usr/bin/Rscript #example : Rscript plot ...
- 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 ...
- Octave中plot函数的用法
octave:14> help plot'plot' is a function from the file C:\Octave\Octave3.6.4_gcc4.6.2\share\octav ...
- 基于MATLAB的多项式数据拟合方法研究-毕业论文
摘要:本论文先介绍了多项式数据拟合的相关背景,以及对整个课题做了一个完整的认识.接下来对拟合模型,多项式数学原理进行了详细的讲解,通过对文献的阅读以及自己的知识积累对原理有了一个系统的认识.介绍多项式 ...
- LaTeX绘图宏包 Pgfplots package
Pgfplots package The pgfplots package is a powerful tool, based on tikz, dedicated to create scienti ...
- Machine Learning and Data Mining(机器学习与数据挖掘)
Problems[show] Classification Clustering Regression Anomaly detection Association rules Reinforcemen ...
- [C2P3] Andrew Ng - Machine Learning
##Advice for Applying Machine Learning Applying machine learning in practice is not always straightf ...
- Exercises for IN1900
Exercises for IN1900October 14, 2019PrefaceThis document contains a number of programming exercises ...
- Maple拥有优秀的符号计算和数值计算能力
https://www.maplesoft.com/products/maple/ Maple高级应用和经典实例: https://wenku.baidu.com/view/f246962107221 ...
随机推荐
- Spring框架整合Struts2框架的传统方法
1. 导入CRM项目的UI页面,找到添加客户的页面,修改form表单,访问Action * 将menu.jsp中133行的新增客户的跳转地址改为:href="${pageContext.re ...
- (转)innodb 多版本并发控制原理详解
转自:https://blog.csdn.net/aoxida/article/details/50689619 多版本并发控制技术已经被广泛运用于各大数据库系统中,如Oracle,MS SQL Se ...
- java读取网页图片路径并下载到本地
java读取网页图片路径并下载到本地 最近公司需要爬取一些网页上的数据,自己就简单的写了一个demo,其中有一些数据是图片,需要下载下来到本地并且 将图片的路径保存到数据库,示例代码如下: packa ...
- 2018.07.06 POJ1273 Drainage Ditches(最大流)
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Description Every time it rains on Farmer J ...
- IDEA如何初始化Git本地仓库,并提交到远程仓库
本文转载自:http://blog.csdn.net/two_people/article/details/77008593 1. 首先在远程仓库上新建一个项目,码云和github都可以,我这里使用的 ...
- MATLAB常用函数
Matlab的内部常数 pi 圆周率 exp(1) 自然对数的底数e i 或j 虚数单位 Inf或 inf ...
- VHDL 中的数据转换函数
2013年8月5日 ieee.std_logic_arith.all SXT:是对std_logic_vector转换成std_logic_vector数据类型,并进行符号扩展. <slv_sx ...
- Oracle之SQL语句性能优化(34条优化方法)
(1)选择最有效率的表名顺序(只在基于规则的优化器中有效): ORACLE的解析器按照从右到左的顺序处理FROM子句中的表名,FROM子句中写在最后的表(基础表 driving table)将被最先处 ...
- 14)settings.xml
1. User Level. ${user.home}/.m2/settings.xml 2. Global Level. ${maven.home}/conf/settings.xml <se ...
- 全面理解iOS开发中的Scroll View[转]
from:http://mobile.51cto.com/hot-430409.htm 可能你很难相信,UIScrollView和一个标准的UIView差异并不大,scroll view确实会多一些方 ...