|
XYZ Line in 3D Plot |
Posted by Vinay Williams on Apr-16-2023 18:12 |
|
Hi,
I am trying to plot a line in a ThreeDChart that is defined by X, Y and Z points, however, I cannot determine how to do this.
Can someone please help here?
Thanks in advance! |
Re: XYZ Line in 3D Plot |
Posted by Peter Kwan on Apr-17-2023 20:57 |
|
Hi Vinay,
If you just want to draw a 3D line and nothing else, you can use ThreeDChart.getXCoor and ThreeDChart.getYCoor to obtain the (x, y) pixel coordinates from the (x, y, z) data values, then you can use BaseChart.addLine to draw a line to connect the points. The following is an example in C#. (If you need to have it translated to another programming language, please let me know.)
// The XYZ data for the 3D scatter chart as 3 random data series
RanSeries r = new RanSeries(0);
double[] xData = r.getSeries2(100, 100, -10, 10);
double[] yData = r.getSeries2(100, 0, 0, 20);
double[] zData = r.getSeries2(100, 100, -10, 10);
// Create a ThreeDScatterChart object of size 640 x 640 pixels
ThreeDScatterChart c = new ThreeDScatterChart(640, 640);
// Set the center of the plot region at (320, 320), and set width x depth x height to 360 x 360
// x 270 pixels
c.setPlotRegion(320, 320, 360, 360, 270);
// Add a transparent scatter group to ensure the axis are auto-scaled to fit the data range
c.addScatterGroup(xData, yData, zData, "", Chart.SquareShape, 1, Chart.Transparent);
// Auto-scale the axis
c.layout();
// Draw the line segments
for (int i = 1; i < xData.Length; ++i)
{
int xCoor = c.getXCoor(xData[i - 1], yData[i - 1], zData[i - 1]);
int yCoor = c.getYCoor(xData[i - 1], yData[i - 1], zData[i - 1]);
int xCoor2 = c.getXCoor(xData[i], yData[i], zData[i]);
int yCoor2 = c.getYCoor(xData[i], yData[i], zData[i]);
c.addLine(xCoor, yCoor, xCoor2, yCoor2, 0xff0000, 2);
}
// Output the chart
viewer.Chart = c;
Best Regards
Peter Kwan
|
Re: XYZ Line in 3D Plot |
Posted by Raimund on Oct-16-2024 16:01 |
|
Thank you very much for the quick and competent answer. It might be useful for future releases to implement 3d lines and others (e.g. 3d arrows) directly. E.G.
RanSeries r = new RanSeries(0);
double[] xData = r.getSeries2(100, 100, -10, 10);
double[] yData = r.getSeries2(100, 0, 0, 20);
double[] zData = r.getSeries2(100, 100, -10, 10);
c.add3dLine(xData,yData,zData);
This would be simpler for the user and possibly faster to execute.
We have been a customer of yours (elmad UG) for some time and use c++.
Regards,
Raimund |
|