lightning chartControl 3D波形图作为G代码路径显示示例

By admin at 2024-07-10 • 1人收藏 • 283人看过

screenshots.gif

没用过这个3d波形图组件, 第一次用调了好久的参数, 才达到我自己的要求.

这个是用的c#的lightningChart图表做的, 运行速度确实没得说. 拖动很流畅

using Arction.WinForms.Charting;
using Arction.WinForms.Charting.Annotations;
using Arction.WinForms.Charting.Series3D;
using Arction.WinForms.Charting.Views.View3D;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Media.Media3D;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        PointLineSeries3D series;
        View3D scene3D;
        Annotation3D targetValueLabel;
        private void Form1_Load(object sender, EventArgs e)
        {
            _chart.ActiveView = ActiveView.View3D;
            _chart.Name = "3D line plot";
            _chart.Title.Visible = false;

            _chart.ColorTheme = ColorTheme.Dark;
            _chart.Background.Color = Color.Black;
            
            series = new PointLineSeries3D(_chart.View3D, Axis3DBinding.Primary, Axis3DBinding.Primary, Axis3DBinding.Primary);
            series.PointStyle.Shape3D = PointShape3D.Sphere;
            series.PointStyle.Size3D.SetValues(0.3, 0.3, 0.3);
            series.Material.DiffuseColor = Color.OrangeRed;
            //series.Material.SpecularColor = Color.Red;
            //series.Material.SpecularPower = 0;
            series.LineVisible = true;
            series.LineStyle.AntiAliasing = LineAntialias.Normal;
            series.LineStyle.Color = Color.FromArgb(100, Color.LightGreen);
            series.LineStyle.Width = 0.1f;
            series.LineStyle.LineOptimization = LineOptimization.Normal;
            series.PointsVisible = true;
            _chart.View3D.PointLineSeries3D.Add(series);

            series.ShowInLegendBox = false;
            scene3D = _chart.View3D;
            scene3D.FrameBox.Style = FrameBox.FrameBoxStyle.Off;

            // Hide walls.
            foreach (WallBase wall in scene3D.GetWalls())
                wall.Visible = false;
            foreach (var item in scene3D.GetAxes())
                item.Visible = false;

            //Add an annotation to show targeted point data
            targetValueLabel = new Annotation3D(scene3D, Axis3DBinding.Primary, Axis3DBinding.Primary, Axis3DBinding.Primary);
            targetValueLabel.TargetCoordinateSystem = AnnotationTargetCoordinates.AxisValues;
            targetValueLabel.LocationCoordinateSystem = CoordinateSystem.RelativeCoordinatesToTarget;
            targetValueLabel.LocationRelativeOffset.SetValues(0, -70);
            targetValueLabel.ArrowLineStyle.Color = Color.Red;
            targetValueLabel.ArrowLineStyle.Width = 2f;
            targetValueLabel.Visible = false;
            targetValueLabel.AllowUserInteraction = false;
            targetValueLabel.Style = AnnotationStyle.RectangleArrow;
            targetValueLabel.Shadow.Visible = false;
            _chart.View3D.Annotations.Add(targetValueLabel);

        }
        static double springHeight = 100;
        static int windingCount = 10;
        static int resolution = 20;            // How frequently points will be added
        static double diameterFactor = 0.2;

        static double angle = 0;               // Begin angle, will be used for tracking current angle
        static double height = 100;            // Begin height, will be used for tracking current spring height

        static double heightStep = springHeight / (windingCount * resolution);
        static double angleStepRad = 2.0 / (double)resolution * Math.PI;

        static double xmax = 0;
        static double xmin = 0;
        static double ymax = 0;
        static double ymin = 0;
        static double zmax = 0;
        static double zmin = 0;

        private void button2_Click(object sender, EventArgs e)
        {
            SeriesPoint3D[] pt = new SeriesPoint3D[1];

            pt[0].X = diameterFactor * Math.Sin(angle) * (height) + 50 / 2.0;
            pt[0].Y = height - 100 + 0.5;
            pt[0].Z = diameterFactor * Math.Cos(angle) * (height) + 50 / 2.0;

            if (pt[0].X>xmax)
            {
                xmax = pt[0].X;
            }
            if (pt[0].X < xmin)
            {
                xmin= pt[0].X;
            }
            if (pt[0].Y > ymax)
            {
                ymax = pt[0].Y;
            }
            if (pt[0].Y < ymin)
            {
                ymin = pt[0].Y;
            }
            if (pt[0].Z > zmax)
            {
                zmax = pt[0].Z;
            }
            if (pt[0].Z < zmin)
            {
                zmin = pt[0].Z;
            }

            

            scene3D.XAxisPrimary3D.SetRange(xmin, xmax);
            scene3D.YAxisPrimary3D.SetRange(ymin, ymax);
            scene3D.ZAxisPrimary3D.SetRange(zmin, zmax);

            targetValueLabel.Visible = true;
            targetValueLabel.TargetAxisValues.SetValues(pt[0].X, pt[0].Y, pt[0].Z);
            //targetValueLabel.Text = $"X:{pt[0].X}\nY:{pt[0].Y}\nZ:{pt[0].Z}";
            angle += angleStepRad;
            height += heightStep;

            series.AddPoints(pt, true);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SeriesPoint3D[] pt = new SeriesPoint3D[1];
            pt[0].X = 20;
            pt[0].Y = 20;
            pt[0].Z = 20;


            series.AddPoints(pt, true);

            scene3D.XAxisPrimary3D.SetRange(xmin, xmax);
            scene3D.YAxisPrimary3D.SetRange(ymin, ymax);
            scene3D.ZAxisPrimary3D.SetRange(zmin, zmax);

            targetValueLabel.Visible = true;
            targetValueLabel.TargetAxisValues.SetValues(pt[0].X, pt[0].Y, pt[0].Z);

            targetValueLabel.Text = $"X:{pt[0].X}\nY:{pt[0].Y}\nZ:{pt[0].Z}";
        }
    }
}

WindowsFormsApp1.zip


1 个回复 | 最后更新于 2024-07-15
2024-07-15   #1


image.png

private void simpleButton3_Click(object sender, EventArgs e)
{
     _chart.View3D.Camera.SetEulerAngles(90, 90, 90);
}

private void simpleButton4_Click(object sender, EventArgs e)

     _chart.View3D.Camera.SetEulerAngles(180, 180, 180);
}

private void simpleButton5_Click(object sender, EventArgs e)
{
     _chart.View3D.Camera.SetEulerAngles(180, 90, 180);
}


登录后方可回帖

登 录
信息栏
 私人小站

本站域名

ChengXu.XYZ

投诉联系:  popdes@126.com



快速上位机开发学习,本站主要记录了学习过程中遇到的问题和解决办法及上位机代码分享

这里主要专注于学习交流和经验分享.
纯私人站,当笔记本用的,学到哪写到哪.
如果侵权,联系 Popdes@126.com

友情链接
Aardio官方
Aardio资源网


才仁机械


网站地图SiteMap

Loading...