3 Replies Latest reply on Mar 6, 2013 1:21 PM by Valkyrie Savage

    Alternative for Surface2 GetProjectedPointOn ?

    Valkyrie Savage

      I found this KB article : https://customerportal.solidworks.com/eservice_enu/start.swe?SWECmd=InvokeMethod&SWEMethod=GotoRecord&SWEService=SWGotoRecord&ViewName=SW+All+Defects+List+customerportal+-+Search&BusObject=Product+Defect&BusComp=Product+Defect&Id=1-11RDEO9 which seems to indicate that the problem I am having, namely that my addin doesn't seem to have enough memory to run getprojectedpointon for purposes of raytracing, is a problem others have had.  It doesn't sound like it has been resolved, either.

       

      So what should I use in lieu of getprojectedpointon ?  Is there a face-, surface-, or feature-level function that will do basically the same thing?  I want to do some raycasting/mirror simulation, and I have to figure out where cast rays hit my parts.

       

      pseudocode:

      for each ray in raySet:

        for each face on body:

          if ray intersects face:

            reflect ray

            if reflectedRay intersects body2:

              insert mirror at ray reflection point on body1

       

      Any thoughts?

        • Re: Alternative for Surface2 GetProjectedPointOn ?
          Artem Taturevych

          Check this - basically the same thing. Just consider the ray direction and start point as the corresponding point and projection direction.

           

          IModelDoc2::RayIntersections.

          ModelDoc2::GetRayIntersectionsPoints.

          ModelDoc2::GetRayIntersectionsTopology.

          __________________________

          Regards,

          Artem Taturevych

          Application Engineer at Intercad

          http://intercad.com.au/

          Tel: +61 2 9454 4444

            • Re: Alternative for Surface2 GetProjectedPointOn ?
              Valkyrie Savage

              I wish I could give you awesome points for knowing the answers to all my questions!

              • Re: Alternative for Surface2 GetProjectedPointOn ?
                Valkyrie Savage

                Are there any examples of this function in use?  I didn't find examples in the documentation, and when I tried to use it, it crashed SolidWorks...  this code has camera.rayVectorOrigins that takes a bunch of MathPoints (about 16) and shoves them into a double[] and camera.rayVectorDirections which does the same thing for MathVectors (also about 16).  I didn't get any error messages, just SolidWorks crashes almost immediately after invoking this function.

                 

                            double[] rayVectorOrigins = camera.rayVectorOrigins();

                            double[] rayVectorDirections = camera.rayVectorDirections();

                 

                 

                            object[] bodies = myComponent.GetBodies2((int)swBodyType_e.swSolidBody);

                 

                 

                            alert("we are trying with component " + myComponent.Name);

                 

                 

                            int numIntersectionsFound = swDoc.RayIntersections(bodies,

                                                                               rayVectorOrigins,

                                                                               rayVectorDirections,

                                                                               (int)(swRayPtsOpts_e.swRayPtsOptsTOPOLS | swRayPtsOpts_e.swRayPtsOptsNORMALS),

                                                                               .01,

                                                                               .01);

                 

                 

                            if (numIntersectionsFound > 0)

                            {

                                double[] horrifyingReturn = swDoc.GetRayIntersectionsPoints();

                                int lengthOfOneReturn = 9;

                                for (int i = 0; i < numIntersectionsFound; i++)

                                {

                                    double bodyIndex = horrifyingReturn[i * lengthOfOneReturn + 0];

                                    double rayIndex = horrifyingReturn[i * lengthOfOneReturn + 1];

                                    double intersectionType = horrifyingReturn[i * lengthOfOneReturn + 2];

                                    double x = horrifyingReturn[i * lengthOfOneReturn + 3];

                                    double y = horrifyingReturn[i * lengthOfOneReturn + 4];

                                    double z = horrifyingReturn[i * lengthOfOneReturn + 5];

                                    double nx = horrifyingReturn[i * lengthOfOneReturn + 6];

                                    double ny = horrifyingReturn[i * lengthOfOneReturn + 7];

                                    double nz = horrifyingReturn[i * lengthOfOneReturn + 8];

                 

                 

                                    alert("our entire horrifying return " + bodyIndex + "," + rayIndex + "," + intersectionType + "," + x + "," + y + "," + z + "," + nx + "," + ny + "," + nz);

                 

                 

                                    alert("we hit body " + ((Body2)bodies[(int)bodyIndex]).Name + " at " + x + "," + y + "," + z);

                 

                 

                                    visualizeRay("cameraRay-" + randomString(15), camera.rayVectors().ElementAt((int)rayIndex), camera.rayVectorSources().ElementAt((int)rayIndex));

                                }

                 

                            }