lightning chartControl 3D波形图作为G代码路径显示示例
By
admin
at 2024-07-10 • 1人收藏 • 526人看过

没用过这个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}";
}
}
}
1 个回复 | 最后更新于 2024-07-15
登录后方可回帖
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); }