Convert Screen Coordinates to Axis Values: View3D

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Arction_LasseP

User avatar
blakeadkins
Posts: 44
Joined: Tue Feb 25, 2014 7:49 pm

Convert Screen Coordinates to Axis Values: View3D

Post by blakeadkins » Tue Feb 25, 2014 7:53 pm

I'm using View3D PointLineSeries3D and I'd like to get the x,y, z values under the mouse, not the screen coordinates.

I saw the example for ViewXY, but that doesn't seem work for the View3D.

Any help would be appreciated. Thanks!

User avatar
ArctionPasi
Posts: 1366
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland

Re: Convert Screen Coordinates to Axis Values: View3D

Post by ArctionPasi » Tue Feb 25, 2014 9:35 pm

Hi,

under the mouse, there's infinite count of positions (a vector from mouse towards the screen), and therefore 2D coordinate can't be directly converted into 3D coordinate. Are you looking for a method that solves the nearest point in PointLineSeries3D?
LightningChart Support Team, PT

User avatar
blakeadkins
Posts: 44
Joined: Tue Feb 25, 2014 7:49 pm

Re: Convert Screen Coordinates to Axis Values: View3D

Post by blakeadkins » Tue Feb 25, 2014 9:55 pm

Yeah, that might work.

User avatar
ArctionPasi
Posts: 1366
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland

Re: Convert Screen Coordinates to Axis Values: View3D

Post by ArctionPasi » Tue Feb 25, 2014 10:03 pm

In MouseMove or MouseClick event handler, seek it like this. Indicate the nearest point with another PLS3D with only one point as a marker.

Code: Select all


private void chart_MouseMove(object sender, MouseEventArgs e)
        {
            Point mouseScreen = e.GetPosition(m_chart);
        
            //Seek from data series 
            int iNearestIndex = GetNearestIndexToMouse(m_chart.View3D.PointLineSeries3D[0], mouseScreen.X, mouseScreen.Y);

            if (iNearestIndex >= 0)
            {
                PointDouble3D nearestPoint = m_chart.View3D.PointLineSeries3D[0].Points[iNearestIndex]; 
                
                m_chart.BeginUpdate();

                //Create another PointLineSeries to show the nearest point with a box. 
                if(m_chart.View3D.PointLineSeries3D.Count < 2)
                {
                    PointLineSeries3D marker = new PointLineSeries3D(m_chart.View3D, Axis3DBinding.Primary, Axis3DBinding.Primary, Axis3DBinding.Primary);
                    marker.PointStyle.Shape = PointShape3D.Box;
                    marker.PointStyle.Size.SetValues(4, 4, 4);
                    marker.Material.DiffuseColor = Color.Lime; 
                    marker.MouseInteraction = false; 
                    m_chart.View3D.PointLineSeries3D.Add(marker); 

                }

                m_chart.View3D.PointLineSeries3D[1].Points = new PointDouble3D[] { nearestPoint };

                m_chart.EndUpdate(); 
            }
       }

int GetNearestIndexToMouse(PointLineSeries3D pls, double mouseX, double mouseY)
        {
         
            PointDouble3D[] points = pls.Points;
            int iPointCount = pls.PointCount;
            PointInt p;
            
            double dMinDistSq = double.MaxValue;
            int iNearestIndex = -1;
            double dDistSq; 
            double x, y;

            //Seek nearest point, by using squared method. It's faster than calling Sqrt every time. 

            for(int i=0;i<iPointCount;i++)
            {
                p = m_chart.View3D.ConvertSeriesValueToScreenCoord(pls, points[i].X, points[i].Y, points[i].Z);
                x = (double) p.X;
                y = (double) p.Y;

                dDistSq = (y - mouseY) * (y - mouseY) + (x - mouseX) * (x - mouseX);
                if (dDistSq < dMinDistSq)
                {
                    dMinDistSq = dDistSq;
                    iNearestIndex = i;
                }
            }

            return iNearestIndex; 

        }

Here, the nearest point is indicated with the lime box.
Nearest 3D point indicated
Nearest 3D point indicated
nearest3DPoint.jpg (274.59 KiB) Viewed 14643 times
8-)
LightningChart Support Team, PT

User avatar
blakeadkins
Posts: 44
Joined: Tue Feb 25, 2014 7:49 pm

Re: Convert Screen Coordinates to Axis Values: View3D

Post by blakeadkins » Wed Feb 26, 2014 4:44 pm

Is there a way to always grab the closest point to the viewer?

User avatar
ArctionPasi
Posts: 1366
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland

Re: Convert Screen Coordinates to Axis Values: View3D

Post by ArctionPasi » Wed Feb 26, 2014 8:08 pm

Kind of. But the mouse must be right over a point.

PointLineSeries3D_0: a polyline, going through all the N points. LineVisible = true, PointsVisible = false, MouseInteraction = false.

PointLineSeries3D_1 ... PointLineSeries3D_N : A series for each point separately. LineVisible = false, PointsVisible = true, Title.ShowInLegendBox = false. Set MouseOverOn/MouseClick event handler for every series. The event handler will launch only for the series that is nearest to camera.
LightningChart Support Team, PT

User avatar
blakeadkins
Posts: 44
Joined: Tue Feb 25, 2014 7:49 pm

Re: Convert Screen Coordinates to Axis Values: View3D

Post by blakeadkins » Fri Feb 28, 2014 9:08 pm

Thanks! Does what I needed.