Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I once found these transformations somewhere on the internet:
public static class ucssen
{
public static Matrix3d DCS2WCS(this Viewport vp) =>
Matrix3d.Rotation(-vp.TwistAngle, vp.ViewDirection, vp.ViewTarget) *
Matrix3d.Displacement(vp.ViewTarget.GetAsVector()) *
Matrix3d.PlaneToWorld(vp.ViewDirection);
public static Matrix3d DCS2WCS2(this Viewport vp) =>
Matrix3d.Rotation(vp.TwistAngle, vp.ViewDirection, vp.ViewTarget) *
Matrix3d.Displacement(vp.ViewTarget.GetAsVector()) *
Matrix3d.PlaneToWorld(vp.ViewDirection);
public static Matrix3d WCS2DCS(this Viewport vp) =>
Matrix3d.WorldToPlane(vp.ViewDirection) *
Matrix3d.Displacement(vp.ViewTarget.GetAsVector().Negate()) *
Matrix3d.Rotation(vp.TwistAngle, vp.ViewDirection, vp.ViewTarget);
public static Matrix3d DCS2PSDCS(this Viewport vp) =>
Matrix3d.Scaling(vp.CustomScale, vp.CenterPoint) *
Matrix3d.Displacement(vp.ViewCenter.Convert3d().GetVectorTo(vp.CenterPoint));
public static Matrix3d PSDCS2DCS(this Viewport vp) =>
Matrix3d.Displacement(vp.CenterPoint.GetVectorTo(vp.ViewCenter.Convert3d())) *
Matrix3d.Scaling(1.0 / vp.CustomScale, vp.CenterPoint);
public static Point3d Convert3d(this Point2d pt) =>
new Point3d(pt.X, pt.Y, 0.0);
}
Which I was using for transforming objects through viewports (so from modelspace to paperspace, and vise versa, like the 'chspace'-command), by:
Matrix3d ViewportToModel = deVp.DCS2WCS() * deVp.PSDCS2DCS();
Matrix3d ModelToViewport = deVp.DCS2PSDCS() * deVp.DCS2WCS2();
However, seems the one ModelToViewport doesn't always work correctly (while lots of times it does). There's some not-logical (to me) displacement I can't explain.
Anyone knows what could be going wrong here?
Solved! Go to Solution.