sort points by different UCS

sort points by different UCS

stefanveurink68AXD
Advocate Advocate
498 Views
2 Replies
Message 1 of 3

sort points by different UCS

stefanveurink68AXD
Advocate
Advocate

Guys, 

 

Not sure if this can be done: 

 

Found this code once to sort a point3dcollection on their x-coordinate: 

 

            Point3dCollection punten2 = new Point3dCollection(
            punten
            .Cast<Point3d>()
            .OrderBy(point => point.X)
            .ToArray());

 


What is needed now is to sort the points on their position in a different UCS. 
However, their original value's need to stay the same. 

Purpose is placing a RotatedDimension.

 

Is this possible to do? Can u give me any direction?

0 Likes
Accepted solutions (1)
499 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor

Something like:

 

Point3dCollection punten2 = new Point3dCollection(
            punten
            .Cast<Point3d>()
            .OrderBy(point => point.X.TranformedBy(ed.CurrentUserCoordinateSystem))
            .ToArray());

I believe calling TransformedBy() in the .OrderBy clause would not change the points in the collection themselves, it only calculates the transform value for sorting, because Point3d is value type, not reference type. That is, Point3d.TransformBy() returns a new Point3d, the original Point3d is not changed, only a copy of it is passed into TransformBy() method. On the other hand. Entity.TransformedBy() is void method, that is, TransformedBy() is applied to the Entity itself.

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 3

_gile
Consultant
Consultant
Accepted solution

I think it should have been:

Matrix3d xform = ed.CurrentUserCoordinateSystem.Inverse();
Point3dCollection punten2 = new Point3dCollection(
    punten
    .Cast<Point3d>()
    .OrderBy(point => point.TranformBy(xform).X)
    .ToArray());


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub