1 Reply Latest reply on Mar 3, 2016 6:40 AM by Brad Phelan

    How to get the vector from any point in the model to the view.

    Brad Phelan

      If I have a point in model space I'd like to know the vector that would join that point to my eye. How to do this with the Solidworks API?

        • Re: How to get the vector from any point in the model to the view.
          Brad Phelan

                  /// <summary>

                  /// Find the vector in model space from the point to the viewers eye.

                  /// </summary>

                  /// <param name="modelView"></param>

                  /// <param name="mathUtility"></param>

                  /// <param name="p"></param>

                  /// <returns></returns>

                  private static MathVector ViewVector(IModelView modelView, IMathUtility mathUtility, IMathPoint p)

                  {

                      var world2screen = modelView.Transform;

                      var pScreen = (MathPoint) p.MultiplyTransform(world2screen);

                      var vv = (IMathVector) mathUtility.CreateVector(new[] {0.0, 0, 1});

                      var pScreenUp = (MathPoint) pScreen.AddVector(vv);

                      var pWorldDelta = (MathPoint) pScreenUp.MultiplyTransform((MathTransform) world2screen.Inverse());

                      var viewVector = (MathVector) p.Subtract(pWorldDelta);

                      return viewVector;

                  }