Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Source/Examples/DrawingLibrary/DrawingLibrary.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net47</TargetFramework>
<PackageId>OxyPlot.ExampleLibrary</PackageId>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Description>Example models for OxyPlot.</Description>
<PackageLicenseUrl>https://raw.githubusercontent.com/oxyplot/oxyplot/master/LICENSE</PackageLicenseUrl>
<Copyright>OxyPlot contributors</Copyright>
<PackageProjectUrl>http://oxyplot.org/</PackageProjectUrl>
<PackageIconUrl>https://raw.githubusercontent.com/oxyplot/oxyplot/develop/Icons/OxyPlot_128.png</PackageIconUrl>
<PackageTags>plotting plot charting chart</PackageTags>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/oxyplot/oxyplot.git</RepositoryUrl>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Examples\UmlClass.cs" />
<Compile Remove="Examples\UmlExamples.cs" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Examples\OpenStreetMapExamples\map.osm" />
<EmbeddedResource Include="Examples\SvgExamples\Ghostscript_Tiger.svgz" />
<EmbeddedResource Include="Resources\Tracklog.gpx" />
<EmbeddedResource Include="Examples\SvgExamples\Ghostscript_Tiger.svg" />
<EmbeddedResource Include="Examples\SvgExamples\Blank_map_of_Europe.svg" />
<EmbeddedResource Include="Examples\OpenStreetMapExamples\mtbways.osm" />
<EmbeddedResource Include="Examples\SvgExamples\Europe_countries.svg" />
</ItemGroup>

<ItemGroup>
<None Include="Examples\UmlClass.cs" />
<None Include="Examples\UmlExamples.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\OxyPlot\OxyPlot.csproj" />
</ItemGroup>
</Project>
18 changes: 18 additions & 0 deletions Source/Examples/DrawingLibrary/Example.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace DrawingDemo
{
using OxyPlot;
using OxyPlot.Drawing;

public class Example
{
public Example(DrawingModel model, IController controller = null)
{
this.Model = model;
this.Controller = controller;
}

public DrawingModel Model { get; set; }

public IController Controller { get; set; }
}
}
14 changes: 14 additions & 0 deletions Source/Examples/DrawingLibrary/ExampleAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace DrawingDemo
{
using System;

public class ExampleAttribute : Attribute
{
public ExampleAttribute(string title)
{
this.Title = title;
}

public string Title { get; set; }
}
}
39 changes: 39 additions & 0 deletions Source/Examples/DrawingLibrary/ExampleInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace DrawingDemo
{
using System;

using OxyPlot.Drawing;

public class ExampleInfo
{
private readonly Func<Example> exampleGetter;

private Example example;

public ExampleInfo(string title, Func<Example> exampleGetter)
{
this.exampleGetter = exampleGetter;
this.Title = title;
}

public string Title { get; set; }

public DrawingModel Model
{
get
{
if (this.example == null)
{
this.example = this.exampleGetter();
}

return this.example.Model;
}
}

public override string ToString()
{
return this.Title;
}
}
}
28 changes: 28 additions & 0 deletions Source/Examples/DrawingLibrary/Examples.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace DrawingDemo
{
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

public static class Examples
{
public static IEnumerable<ExampleInfo> Get()
{
foreach (var type in typeof(Examples).GetTypeInfo().Assembly.DefinedTypes)
{
foreach (var method in type.AsType().GetRuntimeMethods())
{
var exampleAttributes = method.GetCustomAttributes(typeof(ExampleAttribute), true).ToArray();
if (exampleAttributes.Length == 1)
{
var m = method;
yield return
new ExampleInfo(
((ExampleAttribute)exampleAttributes[0]).Title,
() => (Example)m.Invoke(null, null));
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
namespace DrawingLibrary.Examples
{
using System.Collections.Generic;
using System.Linq;

using DrawingDemo;

using OxyPlot;
using OxyPlot.Drawing;

public static class AirfoilExamples
{
[Example("NACA 0012")]
public static Example Naca0012()
{
return Naca4("0012");
}

[Example("NACA 2412")]
public static Example Naca2412()
{
return Naca4("2412");
}

[Example("NACA 6412")]
public static Example Naca6412()
{
return Naca4("6412");
}

public static Example Naca4(string id)
{
var airfoil = new NacaAirfoil(id);
DataPoint[] camberLine;
DataPoint[] upper;
DataPoint[] lower;
DataPoint[] thickness;
airfoil.GetProfile(81, 100, out camberLine, out thickness, out upper, out lower);

var profile = new List<DataPoint>(upper.Reverse());
profile.AddRange(lower);

var drawing = new DrawingModel() { Background = OxyColor.FromRgb(0, 128, 196) };
drawing.Add(new Grid() { MajorColor = OxyColor.FromAColor(20, OxyColors.White), MinorColor = OxyColor.FromAColor(10, OxyColors.White) });
drawing.Add(new Polygon(profile) { Stroke = OxyColors.Blue, Fill = OxyColor.FromAColor(30, OxyColors.White), Thickness = -2 });
drawing.Add(new Polyline(camberLine) { Color = OxyColors.Red, Thickness = -2 });
drawing.Add(new Polyline(thickness) { Color = OxyColors.Purple, Thickness = -2 });
drawing.Add(new Text { Point = new DataPoint(0, 20), Content = "Airfoil example", FontSize = 4, FontWeight = FontWeights.Bold });
drawing.Add(new Text { Point = new DataPoint(0, -7), Content = airfoil.ToString(), FontSize = 3, FontWeight = FontWeights.Bold });
drawing.Add(new Text { Point = new DataPoint(80, -4), Content = "Camber line", FontSize = 2, Color = OxyColors.Red });
drawing.Add(new Text { Point = new DataPoint(80, -7), Content = "Thickness", FontSize = 2, Color = OxyColors.Purple });
drawing.Add(new Rectangle { MinimumX = -2, MaximumX = 102, MinimumY = -12, MaximumY = 22, Stroke = OxyColors.Black });
return new Example(drawing);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
namespace DrawingLibrary.Examples
{
using System;

using OxyPlot;

public class NacaAirfoil
{
public NacaAirfoil()
{
this.MaximumCamber = 0.02;
this.PositionOfMaximumCamber = 0.4;
this.Thickness = 0.12;
}

public NacaAirfoil(string id)
{
this.MaximumCamber = int.Parse(id.Substring(0, 1)) * 0.01;
this.PositionOfMaximumCamber = int.Parse(id.Substring(1, 1)) * 0.1;
this.Thickness = int.Parse(id.Substring(2, 2)) * 0.01;
}

public double Thickness { get; set; }

public double MaximumCamber { get; set; }

public double PositionOfMaximumCamber { get; set; }

public override string ToString()
{
return string.Format("NACA {0}{1}{2}", (int)(this.MaximumCamber * 100), (int)(this.PositionOfMaximumCamber * 10), (int)(this.Thickness * 100));
}

public void GetProfile(int n, double c, out DataPoint[] camberLine, out DataPoint[] thickness, out DataPoint[] upper, out DataPoint[] lower)
{
camberLine = new DataPoint[n];
for (int i = 0; i < n; i++)
{
double beta = Math.PI * i / (n - 1);
double x = c * (1 - Math.Cos(beta)) / 2;
camberLine[i] = new DataPoint(x, Yc(c, x, this.MaximumCamber, this.PositionOfMaximumCamber));
}

upper = new DataPoint[n];
lower = new DataPoint[n];
thickness = new DataPoint[n];

for (int i = 0; i < n; i++)
{
var i0 = i > 0 ? i - 1 : i;
var i1 = i < n - 1 ? i + 1 : i;
var theta = Math.Atan2(camberLine[i1].Y - camberLine[i0].Y, camberLine[i1].X - camberLine[i0].X);

double x = camberLine[i].X;
var yt = Yt(c, x, this.Thickness);
thickness[i] = new DataPoint(x, yt);
upper[i] = new DataPoint(x - yt * Math.Sin(theta), camberLine[i].Y + yt * Math.Cos(theta));
lower[i] = new DataPoint(x + yt * Math.Sin(theta), camberLine[i].Y - yt * Math.Cos(theta));
}
}

private static double Yt(double c, double x, double t)
{
var xc = x / c;
return t / 0.2 * c * ((0.2969 * Math.Sqrt(xc)) - (0.126 * xc) - (0.3516 * xc * xc) + (0.2843 * xc * xc * xc) - (0.1015 * xc * xc * xc * xc));
}

private static double Yc(double c, double x, double m, double p)
{
if (x < p * c)
{
return m * x / (p * p) * ((2 * p) - (x / c));
}

return m * (c - x) / ((1 - p) * (1 - p)) * (1 + (x / c) - (2 * p));
}
}
}
Loading