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 ...
随机推荐
- Mina入门:mina版之HelloWorld[z]
Mina入门:mina版之HelloWorld [z] 一,前言: 在完成上篇文章<Mina入门:Java NIO框架Mina.Netty.Grizzly简介与对比>之后,我们现在可以正式 ...
- htons、htonl与字节序大小端
判断字节序大小端code #include <stdio.h> int main() { ) == ) printf("big endian\n"); else pri ...
- 系统调用方式文件编程-open
通过Linux系统调用函数编写应用程序,该应用程序实现文件的复制功能 文件描述符--在Linux系统中,所有打开的文件也对应一个数字,这个数字由系统来分配. 1.打开文件--open 头文件:#inc ...
- python之BeautifulSoup模块
# 名称修改(bs4) from bs4 import BeautifulSoup 帮助文档 Beautiful Soup parses a (possibly invalid) XML or HTM ...
- android触控,先了解MotionEvent(一)
http://my.oschina.net/banxi/blog/56421 这是我个人的看法,要学好android触控,了解MotionEvent是必要,对所用的MotionEvent常用的API要 ...
- Vim配置(转)
1.按F5可以直接编译并执行C.C++.java代码以及执行shell脚本,按“F8”可进行C.C++代码的调试 2.自动插入文件头 ,新建C.C++源文件时自动插入表头:包括文件名.作者.联系方式. ...
- Linux服务器部署系列之七—OpenLDAP篇
LDAP(轻量级目录访问服务),通过配置这个服务,我们也可以在linux下面使用目录的形式管理用户,就像windows下面的AD一样,方便我们管理.下面我们就一起来配置openldap服务.本文运行环 ...
- POJ 1458 Common Subsequence (DP+LCS,最长公共子序列)
题意:给定两个字符串,让你找出它们之间最长公共子序列(LCS)的长度. 析:很明显是个DP,就是LCS,一点都没变.设两个序列分别为,A1,A2,...和B1,B2..,d(i, j)表示两个字符串L ...
- 201521123014《Java程序设计》第1周学习总结
201521123014 java第一周总结 1.本周学习总结 刚认识这一门新语言,我就充满了好奇心,想看看Java和学过C语言,C++有什么区别.在这一周的学习中,我认识到,对于初学者而言,Java ...
- Memcached 应用场景
1. 把java对象序列化成base64 存入缓存,不同平台可以反序列化. 2. 通过key去重复 3. 保存一些信息,供所有平台使用