Vector3d.ProjectTo not working as expected

Vector3d.ProjectTo not working as expected

Anonymous
Not applicable
1,107 Views
5 Replies
Message 1 of 6

Vector3d.ProjectTo not working as expected

Anonymous
Not applicable

I want to project an mtext direction vector onto the z plane. The thing is I don't want an orthogonal projection, I need to project it in the same direction of the mtext's direction vector. I don't know how to explain it right.

 

This is what I tried to do:

 

Vector3d proy = mtext.Direction.ProjectTo(Vector3d.ZAxis, mtext.Direction);

This returns (0,0,0), which obviously isn't the result I'm expecting. 

0 Likes
Accepted solutions (1)
1,108 Views
5 Replies
Replies (5)
Message 2 of 6

_gile
Consultant
Consultant

Hi,

 

Whatever the projection plane, if you project a vector using this vector direction, you'll always get a null vector (this is what the code you show does).

You should explain what you're trying to achieve and or provide some drawing



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 6

Anonymous
Not applicable

My aim is to transform ANY mtext so it's looking upwards (it's normal vector equals (0, 0, 1)).

 

I don't want the mtext's rotation, etc.. to be altered, so I'm doing this using the TransformBy() method.

 

I want to achieve this in two steps:

 

1 - Rotate the mtext's normal's perpendicular vector

 

 

Vector3d mtextRotatedNormal = mtext.Normal.TransformBy(Matrix3d.Rotation(Math.PI / 2, mtext.Direction, mtext.Location));

Until the direction vector's Z value equals 0 (I need to calculate the correct angle for this transformation).

 

2- Rotate the mtext's direction vector until the mtextRotatedNormal vector's Z value equals 0.

 

With these two steps the mtext's normal should equal (0, 0, 1) but I cannot obtain the right angles for the rotations.

 

I was trying to obtain that vector for the calculation of the first angle.

 

 

0 Likes
Message 4 of 6

_gile
Consultant
Consultant

This should work:

var location = mtext.Location;
var plane = new Plane(Point3d.Origin, mtext.Normal);
mtext.TransformBy(Matrix3d.WorldToPlane(plane));
mtext.Location = location;


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 6

Anonymous
Not applicable

I tried something similar. It almost works but it's direction vector is not correct.

 

When I execute the code you provided, the mtext's direction is changed.

0 Likes
Message 6 of 6

_gile
Consultant
Consultant
Accepted solution

Like this?

var pt = mtext.Location;
double rot = Vector3d.XAxis.GetAngleTo(mtext.Direction, Vector3d.ZAxis);
var plane = new Plane(Point3d.Origin, mtext.Normal);
mtext.TransformBy(Matrix3d.WorldToPlane(plane));
mtext.Location = pt;
mtext.Rotation = rot;


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes