.NET

Reply
Valued Contributor
95 Posts
3 Kudos
Registered: ‎04-04-2012
Post 1 of 5
Accepted Solution

Rotating a 3dPolyline

278 Views, 4 Replies
04-07-2013 07:39 PM

Hi,

 

I am trying to rotate a 3dPolyline, so that I can check(view) the Z-value of vertices in the top-view mode.

The following is the example which I am trying to achieve.

 

K-1.png

 

The white 3dPolyline has vertices at each intersecting point with the contour lines.

Each vertax has Z-value.

I want to rotate this white 3dPolyline in 3D, so that I can make the red 2dPolyline. (Z-value becomes Y-value)

And the start point of the white 3dPolyline becomes the left most point of the red line.

The end point of the white 3dPolyline becomes the right most point of the red line.

 

Currently, I am doing this by making a new 2dPolyline, manually inserting Z-values as Y-values.

 

But it looks like my code can be neater if I use TrnasformBy(Matrix3d.Projection).

Sadly, I am not good with Geometry, so it's bit hard for me to figure out how to use this Matrix3d.Projection.

 

Could anyone write me a quick code snippet to make this function? (preferably in C#)

 

Thank you in advance.

 

 

Hi,

 

A little too late...

 

Point3d startPnt = pl3d.StartPoint;
Vector3d vect = pl3d.EndPoint - startPnt;
double angle = vect.GetAngleTo(Vector3d.XAxis, Vector3d.ZAxis);
pl3d.TransformBy(
Matrix3d.Displacement(basePnt - startPnt) *
Matrix3d.Rotation(Math.PI / -2.0, Vector3d.XAxis, startPnt) *
Matrix3d.Rotation(angle, Vector3d.ZAxis, startPnt));

 

ADN Support Specialist
352 Posts
27 Kudos
Registered: ‎07-24-2007
Post 2 of 5

Re: Rotating a 3dPolyline

04-08-2013 03:15 PM in reply to: dynamicscope

can you post the DWG file maybe?





Fenton Webb

Developer Technical Services

Autodesk Developer Network


Valued Contributor
95 Posts
3 Kudos
Registered: ‎04-04-2012
Post 3 of 5

Re: Rotating a 3dPolyline

04-09-2013 07:01 PM in reply to: dynamicscope

I found an another way around.

Rotating twice and displace it!! =)

 

Polyline3d pl3d = ent as Polyline3d;

double a = MyMath.GetAzimuth(pl3d.StartPoint, pl3d.EndPoint);
Matrix3d mat = Matrix3d.Rotation(a - (Math.PI / 2), new Vector3d(0, 0, 1), pl3d.StartPoint);                                        
pl3d.TransformBy(mat);

Matrix3d mat2 = Matrix3d.Rotation(3 * Math.PI / 2, new Vector3d(1, 0, 0), pl3d.StartPoint);
pl3d.TransformBy(mat2);

Vector3d v = new Vector3d(basePnt.X - pl3d.StartPoint.X, basePnt.Y - pl3d.StartPoint.Y, basePnt.Z - pl3d.StartPoint.Z);
Matrix3d mat3 = Matrix3d.Displacement(v);
pl3d.TransformBy(mat3);

 

Thank you for your time anyway~ =)

*Expert Elite*
2,142 Posts
255 Kudos
Registered: ‎04-29-2006
Post 4 of 5

Re: Rotating a 3dPolyline

04-10-2013 03:04 AM in reply to: dynamicscope

Hi,

 

A little too late...

 

Point3d startPnt = pl3d.StartPoint;
Vector3d vect = pl3d.EndPoint - startPnt;
double angle = vect.GetAngleTo(Vector3d.XAxis, Vector3d.ZAxis);
pl3d.TransformBy(
    Matrix3d.Displacement(basePnt - startPnt) *
    Matrix3d.Rotation(Math.PI / -2.0, Vector3d.XAxis, startPnt) *
    Matrix3d.Rotation(angle, Vector3d.ZAxis, startPnt));

 

Gilles Chanteau
Valued Contributor
95 Posts
3 Kudos
Registered: ‎04-04-2012
Post 5 of 5

Re: Rotating a 3dPolyline

04-14-2013 05:32 PM in reply to: _gile

Didn't know I can write it this simple.
Thank you very much~!

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!