C# 如何在二维网格上绘制张量可视化

C# 如何在二维网格上绘制张量可视化,c#,math,C#,Math,我想实现(一个c#程序)本文中的系统,它使用张量场来设计街道网络。对于我的实现,我的首要任务是从我自己的张量场生成我自己的街道网络。一开始我不想要太高级的东西。论文说,张量线(主特征向量和次特征向量)将代表街道。 有人知道我应该从哪里开始看(如何在二维网格中绘制这些线)吗。在这篇论文中有一些参考文献,比如张量场可视化论文,但我无法停止在一个循环中寻找一个参考文献到另一个参考文献 问候。我假设这是您需要帮助的绘图部分。C#有许多绘图功能,可以很容易地画出这样的东西。GDI+(System.draw

我想实现(一个c#程序)本文中的系统,它使用张量场来设计街道网络。对于我的实现,我的首要任务是从我自己的张量场生成我自己的街道网络。一开始我不想要太高级的东西。论文说,张量线(主特征向量和次特征向量)将代表街道。 有人知道我应该从哪里开始看(如何在二维网格中绘制这些线)吗。在这篇论文中有一些参考文献,比如张量场可视化论文,但我无法停止在一个循环中寻找一个参考文献到另一个参考文献


问候。

我假设这是您需要帮助的绘图部分。C#有许多绘图功能,可以很容易地画出这样的东西。GDI+(System.drawing中包含的图形/绘图软件包)内置了对2D转换的支持,因此我们可以创建位图,然后使用任意坐标系在其上绘图。您还可以利用System.Windows命名空间中现有的Vector类来简化向量数学

首先,您需要的名称空间和程序集:

using System;

// Needs reference to System.Drawing to use GDI+ for drawing
using System.Drawing; 
using System.Drawing.Imaging;

// Needs reference to WindowBase to use Vector class
using Vector = System.Windows.Vector;
下面的示例只是绘制了一个10x10的矢量网格。代码的输出将在控制台应用程序内部正常运行(即没有用户界面)。您还可以修改代码以生成位图,并通过图片框或其他一些UI元素显示在Windows窗体应用程序中。不过,控制台版本非常简单,易于使用:

// Define the size of our viewport using arbitary world coordinates
var viewportSize = new SizeF(10, 10);

// Create a new bitmap image that is 500 by 500 pixels
using (var bmp = new Bitmap(500, 500, PixelFormat.Format32bppPArgb))
{
    // Create graphics object to draw on the bitmap
    using (var g = Graphics.FromImage(bmp))
    {
        // Set up transformation so that drawing calls automatically convert world coordinates into bitmap coordinates
        g.TranslateTransform(0, bmp.Height * 0.5f - 1);
        g.ScaleTransform(bmp.Width / viewportSize.Width, -bmp.Height / viewportSize.Height);
        g.TranslateTransform(0, -viewportSize.Height * 0.5f);

        // Create pen object for drawing with
        using (var redPen = new Pen(Color.Red, 0.01f)) // Note that line thickness is in world coordinates!
        {
            // Randomization
            var rand = new Random();

            // Draw a 10x10 grid of vectors
            var a = new Vector();
            for (a.X = 0.5; a.X < 10.0; a.X += 1.0)
            {
                for (a.Y = 0.5; a.Y < 10.0; a.Y += 1.0)
                {
                    // Connect the center of this cell to a random point inside the cell
                    var offset = new Vector(rand.NextDouble() - 0.5, rand.NextDouble() - 0.5);
                    var b = a + offset;
                    g.DrawLine(redPen, a.ToPointF(), b.ToPointF());
                }
            }
        }
    }

    // Save the bitmap and display it
    string filename = System.IO.Path.Combine(
        Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
        "c#test.png");
    bmp.Save(filename, ImageFormat.Png);
    System.Diagnostics.Process.Start(filename);
}
//使用任意世界坐标定义视口的大小
var viewportSize=newsizef(10,10);
//创建500 x 500像素的新位图图像
使用(var bmp=新位图(500500,PixelFormat.Format32bppPArgb))
{
//创建要在位图上绘制的图形对象
使用(var g=Graphics.FromImage(bmp))
{
//设置转换,以便图形调用自动将世界坐标转换为位图坐标
g、 TranslateTransform(0,bmp.Height*0.5f-1);
g、 ScaleTransform(bmp.Width/viewportSize.Width,-bmp.Height/viewportSize.Height);
g、 TranslateTransform(0,-viewportSize.Height*0.5f);
//使用创建绘图笔对象
使用(var redPen=new Pen(Color.Red,0.01f))//注意线的厚度是在世界坐标中!
{
//随机化
var rand=new Random();
//绘制一个10x10的矢量网格
var a=新向量();
对于(a.X=0.5;a.X<10.0;a.X+=1.0)
{
对于(a.Y=0.5;a.Y<10.0;a.Y+=1.0)
{
//将此单元的中心连接到单元内的随机点
变量偏移=新向量(rand.NextDouble()-0.5,rand.NextDouble()-0.5);
var b=a+偏移量;
g、 抽绳(红色,a.ToPointF(),b.ToPointF());
}
}
}
}
//保存位图并显示它
字符串文件名=System.IO.Path.Combine(
GetFolderPath(Environment.SpecialFolder.MyDocuments),
“c#test.png”);
保存(文件名,ImageFormat.Png);
System.Diagnostics.Process.Start(文件名);
}

我假设这是您需要帮助的绘图部件。C#有许多绘图功能,可以很容易地画出这样的东西。GDI+(System.drawing中包含的图形/绘图软件包)内置了对2D转换的支持,因此我们可以创建位图,然后使用任意坐标系在其上绘图。您还可以利用System.Windows命名空间中现有的Vector类来简化向量数学

首先,您需要的名称空间和程序集:

using System;

// Needs reference to System.Drawing to use GDI+ for drawing
using System.Drawing; 
using System.Drawing.Imaging;

// Needs reference to WindowBase to use Vector class
using Vector = System.Windows.Vector;
下面的示例只是绘制了一个10x10的矢量网格。代码的输出将在控制台应用程序内部正常运行(即没有用户界面)。您还可以修改代码以生成位图,并通过图片框或其他一些UI元素显示在Windows窗体应用程序中。不过,控制台版本非常简单,易于使用:

// Define the size of our viewport using arbitary world coordinates
var viewportSize = new SizeF(10, 10);

// Create a new bitmap image that is 500 by 500 pixels
using (var bmp = new Bitmap(500, 500, PixelFormat.Format32bppPArgb))
{
    // Create graphics object to draw on the bitmap
    using (var g = Graphics.FromImage(bmp))
    {
        // Set up transformation so that drawing calls automatically convert world coordinates into bitmap coordinates
        g.TranslateTransform(0, bmp.Height * 0.5f - 1);
        g.ScaleTransform(bmp.Width / viewportSize.Width, -bmp.Height / viewportSize.Height);
        g.TranslateTransform(0, -viewportSize.Height * 0.5f);

        // Create pen object for drawing with
        using (var redPen = new Pen(Color.Red, 0.01f)) // Note that line thickness is in world coordinates!
        {
            // Randomization
            var rand = new Random();

            // Draw a 10x10 grid of vectors
            var a = new Vector();
            for (a.X = 0.5; a.X < 10.0; a.X += 1.0)
            {
                for (a.Y = 0.5; a.Y < 10.0; a.Y += 1.0)
                {
                    // Connect the center of this cell to a random point inside the cell
                    var offset = new Vector(rand.NextDouble() - 0.5, rand.NextDouble() - 0.5);
                    var b = a + offset;
                    g.DrawLine(redPen, a.ToPointF(), b.ToPointF());
                }
            }
        }
    }

    // Save the bitmap and display it
    string filename = System.IO.Path.Combine(
        Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
        "c#test.png");
    bmp.Save(filename, ImageFormat.Png);
    System.Diagnostics.Process.Start(filename);
}
//使用任意世界坐标定义视口的大小
var viewportSize=newsizef(10,10);
//创建500 x 500像素的新位图图像
使用(var bmp=新位图(500500,PixelFormat.Format32bppPArgb))
{
//创建要在位图上绘制的图形对象
使用(var g=Graphics.FromImage(bmp))
{
//设置转换,以便图形调用自动将世界坐标转换为位图坐标
g、 TranslateTransform(0,bmp.Height*0.5f-1);
g、 ScaleTransform(bmp.Width/viewportSize.Width,-bmp.Height/viewportSize.Height);
g、 TranslateTransform(0,-viewportSize.Height*0.5f);
//使用创建绘图笔对象
使用(var redPen=new Pen(Color.Red,0.01f))//注意线的厚度是在世界坐标中!
{
//随机化
var rand=new Random();
//绘制一个10x10的矢量网格
var a=新向量();
对于(a.X=0.5;a.X<10.0;a.X+=1.0)
{
对于(a.Y=0.5;a.Y<10.0;a.Y+=1.0)
{
//将此单元的中心连接到单元内的随机点
变量偏移=新向量(rand.NextDouble()-0.5,rand.NextDouble()-0.5);
var b=a+偏移量;
g、 抽绳(红色,a.ToPointF(),b.ToPointF());
}
}
}
}
//保存位图并显示它
字符串文件名=System.IO.Path.Combine(
GetFolderPath(Environment.SpecialFolder.MyDocuments),
“c#test.png”);
保存(文件名,ImageFormat.Png);
System.Diagnostics.Process.Start(文件名);
}

您需要做大量的工作