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. dump()

    输出格式化的对象

  2. 网站SEO优化的方法

    网站SEO优化的方法: 1.url静态化和规范化:url中都去掉了index.php这样的后缀网址形式,目的就是让网站的层级更浅,获得的权重更高 代码中可以使用urlrewrite重写. 2.域名30 ...

  3. mysql的UseAffectedRows问题 以及其他常见配置说明

    遇到MySQL中on duplicate key update语句返回值不正确: 在server5.1.*的返回分别为insert=1,update=3,nochange=2 在server5.5.* ...

  4. 2018.10.18 NOIP训练 [SCOI2018]Pipi 酱的日常(线段树)

    传送门 线段树好题啊. 题目要求的是sum−a−b−c+maxsum-a-b-c+maxsum−a−b−c+max{∣a+v∣+∣b+v∣+∣c+v∣|a+v|+|b+v|+|c+v|∣a+v∣+∣b ...

  5. 2018.08.06bzoj1251: 序列终结者(非旋treap)

    传送门 平衡树板子题. 直接fhqtreap打区间标记就行了. 代码: #include<bits/stdc++.h> #define N 50005 using namespace st ...

  6. Java中读取.properties配置文件的通用类

    由于Java中读取配置文件的代码比较固定,所以可以将读取配置文件的那部分功能单独作为一个类,以后可以复用.为了能够达到复用的目的,不能由配置文件中每一个属性生成一个函数去读取,我们需要一种通用的方法读 ...

  7. Django 必会面试题总结

    1 列举Http请求中常见的请求方式 HTTP请求的方法: HTTP/1.1协议中共定义了八种方法(有时也叫“动作”),来表明Request-URL指定的资源不同的操作方式   注意: 1)方法名称是 ...

  8. java拷贝文件到另一个目录下

    package com.util; import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream ...

  9. jquery文件上传控件 WebUploader

    WebUploader是百度开源的一个文件上传组件,因为其操作简洁大方,就在项目中使用了,记录一下. 效果是这样子:  这个样子是默认的效果.  这个是选择上传的图片,可以批量,选择后可以删除和添加更 ...

  10. java 泛型的类型擦除和桥方法

    oracle原文地址:https://docs.oracle.com/javase/tutorial/java/generics/erasure.html 在Java中,泛型的引入是为了在编译时提供强 ...