Problem with VieTableRecord CenterPoint vs Target

Problem with VieTableRecord CenterPoint vs Target

mario.rosenbohm
Explorer Explorer
646 Views
7 Replies
Message 1 of 8

Problem with VieTableRecord CenterPoint vs Target

mario.rosenbohm
Explorer
Explorer

Hello,

 

i have a big problem with th ViewTableRecord.

From this i will read the coordinate from current view rectangle for build the search frame.

I habe two dwg's both i view Width ~5800 hand Height ~2400, both ViewOrthographic is TopView and all other relevant Properties are equal.

On first dwg is the Target (0,0,0) and the CenterPoint (2659.5,1429.4) get the coordinate from real center.

On the second dwg is the Target (4432100,5612220,0) and the CenterPoint (2192.7,1215.0). Here get the Target the real center.

 

Why it is?

How can i detect whether CenterPoint or Target take the real Center?

 

regards Mario

0 Likes
647 Views
7 Replies
Replies (7)
Message 2 of 8

_gile
Consultant
Consultant

Hi,

I'm not sure to understand what you mean with "real Center".

You have to keep in mind the view Target is a WCS 3d point and the view centerPoint is a DCS 2d point.

You can use these extension methods adapted from this library to transform points.

 

/// <summary>
    /// Provides extension for the AbstractViewTableRecord type.
    /// </summary>
    public static class AbstractViewTableRecordExtension
    {
        /// <summary>
        /// Gets the transformation matrix from the view Display Coordinate System (DCS) to World Coordinate System (WCS).
        /// </summary>
        /// <param name="view">Instance to which the method applies.</param>
        /// <returns>The DCS to WCS transformation matrix.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown if <paramref name ="view"/> is null.</exception>
        public static Matrix3d EyeToWorld(this AbstractViewTableRecord view)
        {
            if (view is null) throw new System.ArgumentNullException(nameof (view));

            return
                Matrix3d.Rotation(-view.ViewTwist, view.ViewDirection, view.Target) *
                Matrix3d.Displacement(view.Target.GetAsVector()) *
                Matrix3d.PlaneToWorld(view.ViewDirection);
        }

        /// <summary>
        /// Gets the transformation matrix from World Coordinate System (WCS) to the view Display Coordinate System (DCS).
        /// </summary>
        /// <param name="view">Instance to which the method applies.</param>
        /// <returns>The WCS to DCS transformation matrix.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown if <paramref name ="view"/> is null.</exception>
        public static Matrix3d WorldToEye(this AbstractViewTableRecord view)
        {
            if (view is null) throw new System.ArgumentNullException(nameof (view));

            return
                Matrix3d.WorldToPlane(view.ViewDirection) *
                Matrix3d.Displacement(view.Target.GetAsVector().Negate()) *
                Matrix3d.Rotation(view.ViewTwist, view.ViewDirection, view.Target);
        }
    }

 

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 8

mario.rosenbohm
Explorer
Explorer

Hello Gilles,

yes i know and i use the functions to transform the viewpoint coordinates. In (first) test.dwg is the left bottom viewcorner (-158.8,217.8) the ViewPort.Centerpoint considered this displacement. But the matrix as result of function is identity matrix!?  Viewport.Target is 0,0,0!?

 

regards Mario

0 Likes
Message 4 of 8

_gile
Consultant
Consultant

This should work:

var ed = Application.DocumentManager.MdiActiveDocument.Editor;
using (var view = ed.GetCurrentView())
{
    var viewCenterPoint = view.CenterPoint;
    var wcsCenterPoint = new Point3d(viewCenterPoint.X, viewCenterPoint.Y, 0.0).TransformBy(view.EyeToWorld());
}


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 8

mario.rosenbohm
Explorer
Explorer

Hello Gilles,

 

okay, for the test.dwg it works.

I have two another dwg files test2.dwg and test3.dwg on both is the "real centerpoint" on (32439596.0, 5967780.0).

On test2.dwg (is only test.dwg with 'moveto') it the sam ViewPort as test.dwg (CenterPoint = (32439596.0, 5967780.0,0) and Target = (0,0,0)

"test3.dwg" is 'wblock' from my working-dwg, this has no civil-elements, has no coordinate system, is create from plain autocad-template. On this dwg is the ViewPort CenterPoint=(27697465.988,356748.777) and Target=(4742130.012,5611031.223,0.0).

 

What ist the function of Target and CenterPoint?

0 Likes
Message 6 of 8

mario.rosenbohm
Explorer
Explorer

sorry i forgotten the files

0 Likes
Message 7 of 8

mario.rosenbohm
Explorer
Explorer

I use the CenterPoint as startpoint for transformation and the target as displacement.
I hope thats right 😉

0 Likes
Message 8 of 8

_gile
Consultant
Consultant

Sorry, I'm afraid to not fully understand what you want to do.

The following TEST command, computes the current viewport center using the upper extension methods and draws a temporary red cross on this point. From the tests I did it works whatever the curent view (even 3d orbited).

        public void Test()
        {
            var ed = Application.DocumentManager.MdiActiveDocument.Editor;
            using (var view = ed.GetCurrentView())
            {
                var viewCenterPoint = view.CenterPoint;
                var wcsCenterPoint = new Point3d(viewCenterPoint.X, viewCenterPoint.Y, 0.0).TransformBy(view.EyeToWorld());
                double d = view.Height / 50.0;
                using (var resbuf = new ResultBuffer
                {
                    new TypedValue(5003, 1),
                    new TypedValue(5002, new Point2d(wcsCenterPoint.X - d, wcsCenterPoint.Y - d)),
                    new TypedValue(5002, new Point2d(wcsCenterPoint.X + d, wcsCenterPoint.Y + d)),
                    new TypedValue(5002, new Point2d(wcsCenterPoint.X - d, wcsCenterPoint.Y + d)),
                    new TypedValue(5002, new Point2d(wcsCenterPoint.X + d, wcsCenterPoint.Y - d))
                })
                    ed.DrawVectors(resbuf, Matrix3d.Identity);
            }
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes