cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Finding distance from the model

SOLVED
Highlighted
Amethyst

Finding distance from the model

Is there a way to know how far the model is placed from us?

For eg. when I scan a object using model target and my model is superimposed over that object. Now I want to know how far am i standing from that object. And when I move around the distance shown should also change.

 

Any support or suggestion how it can be achieved will be very helpful.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: Finding distance from the model

Hi @vivekse ,

 

yes, this this is correct.  I checked it in a mobile project but it was not working stable. 

So,I tested somethings furter and have now a mobile project where it seems to work now - means you will received the coordinates of the eye positon , gaze vector and the up vector.

I tested in preview (this is only simulation for mobile device- so that the results/values are not relevant) but I tested it also on IOS Ipad6 and was working with the current Vuforia Viewver version:

 

2020-02-05_12-17-49.gif

the code :

 

function magnitute(a1,a2,a3)
{

return Math.sqrt( Math.pow(a1, 2) + Math.pow(a2, 2)+ Math.pow(a3, 2));
}

function cross(a1,a2,a3, b1,b2,b3) 
{
 return [ a2 * b3 - a3 * b2, a3 * b1 - a1 * b3, a1 * b2 - a2 * b1 ];
}
function normalizeVector(a1,a2,a3) {
    var mag = magnitute(a1,a2,a3)
    return new Vector(a1/mag, a2/mag, a3/mag);
};

/////////////////////////////////////
$rootScope.$on('modelLoaded', function() { 
 
    
   $scope.setWidgetProp('3DContainer-1','enabletrackingevents',true);
  console.log("now check again the setting of the envronment")
  console.warn($scope.app.view.Home.wdg['3DContainer-1'].enabletrackingevents)
  
  //// end of modelLoaded
});
//=============================================================
 $rootScope.$on('tracking', function( tracker,fargs  ) {
  
  console.warn(fargs.position);
 
   $scope.app.params['eyepos'] ="eyepos=("+fargs.position[0].toFixed(2)+","+fargs.position[1].toFixed(2)+","+fargs.position[2].toFixed(2)+")";
   $scope.app.params['eyedir'] ="eyedir=("+fargs.gaze[0].toFixed(2)+","+fargs.gaze[1].toFixed(2)+","+fargs.gaze[2].toFixed(2)+")";
   $scope.app.params['eyeup' ] ="eyeup =("+fargs.up[0].toFixed(2)+","+ fargs.up[1].toFixed(2)+","+fargs.up[2].toFixed(2)+")";
   var scale=1.3;
   $scope.setWidgetProp('3DImage-1',  'x', ( fargs.position[0]+fargs.gaze[0]*scale));
   $scope.setWidgetProp('3DImage-1',  'y', ( fargs.position[1]+fargs.gaze[1]*scale));
   $scope.setWidgetProp('3DImage-1',  'z', ( fargs.position[2]+fargs.gaze[2]*scale));
  //3DLabel-1 no y
   $scope.setWidgetProp('label-distance-x',  'x', ( fargs.position[0]+fargs.gaze[0]*scale)+0.0);
   $scope.setWidgetProp('label-distance-x',  'y', ( fargs.position[1]+fargs.gaze[1]*scale) -0.08*5);
   $scope.setWidgetProp('label-distance-x',  'z', ( fargs.position[2]+fargs.gaze[2]*scale));
   $scope.setWidgetProp('label-distance-y',  'x', ( fargs.position[0]+fargs.gaze[0]*scale)+0.0);
   $scope.setWidgetProp('label-distance-y',  'y', ( fargs.position[1]+fargs.gaze[1]*scale)-0.08*4);
   $scope.setWidgetProp('label-distance-y',  'z', ( fargs.position[2]+fargs.gaze[2]*scale));
   $scope.setWidgetProp('label-distance-z',  'x', ( fargs.position[0]+fargs.gaze[0]*scale)+0.0);
   $scope.setWidgetProp('label-distance-z',  'y', ( fargs.position[1]+fargs.gaze[1]*scale)-0.08*3);
   $scope.setWidgetProp('label-distance-z',  'z', ( fargs.position[2]+fargs.gaze[2]*scale));

   
   console.info("distance to 0,0,0 World CSYS = :: "+magnitute(fargs.position[0].toFixed(2),fargs.position[1].toFixed(2),fargs.position[2].toFixed(2)) )
  
 $scope.$applyAsync();
});
                            

 

In the parameter eyepos, eyedir and eyeup I created binding to the text property of the lables label-dinstance-x/y/z and are displayed there.

I attached the test project

View solution in original post

15 REPLIES 15
Highlighted

Re: Finding distance from the model

Hi @vivekse ,

I think after some preparation yes. 

The question what do you mean with model. Is this the 3d geometry which is loaded as model data or you means some geometry on the real word. For example, a surface where you have set the space target....

I believe you mean here the model( model widget) in this case you need to check you model and need to know  e.g. what is the distance of some part what you need to check to the model widget   or modelItem coordinate  system.

Because what you can measure is the current position of your device in regards of  the world 0,0,0 coordinate system. From there you can calculated the distance to e.g. modelItem or model references but you cannot find  the distance to specific  a point e.g. on a surface . I think you can check also the following post

"https://community.ptc.com/t5/Vuforia-Studio/Get-surface-coordinates-of-a-model/m-p/646408#M7459"

Highlighted

Re: Finding distance from the model

Thankyou @RolandRaytchev for your reply.

 

Actually by model, I meant the model widget. Can you send me an example so that I could understand it in a better way? 

Highlighted

Re: Finding distance from the model

Hi @vivekse ,

thanks for the feedback, but as I see you did a little misunderstood my message, therefore, please let me explain.

Let consider what is the start setting:

  • You have a model widget and you need to have the information about distance to it.
  • The model widget has a specific position according to the world coordinate system. This is defined by the model widget properties for translations x,y,z and rx,ry and rz for rotations
  • What you could measure now is the current position of your device to the global coordinate system. And then you can calculate the position to the coordinate system of the model widget and  as I already mentioned in the previous post  “From there you can calculated the distance to e.g. modelItem or model references but you cannot find the distance to specific point e.g. on a surface .”

The mention post "https://community.ptc.com/t5/Vuforia-Studio/Get-surface-coordinates-of-a-model/m-p/646408#M7459" demonstrate  how to received the current position of your device.

In your case you have to add  to x,y,z, rx, ry, rz of you model to calculate the distance of your device to the model or (better) modelItem coordinate system - something like this:

 

 

 

//////////////////////////////////// 
$rootScope.$on('modelLoaded', function() 
{ $scope.check_if_works=false 
//===================== 
// set some properties 
//the next prop is important that the tracking event will use the callback
$scope.setWidgetProp('3DContainer-1','enabletrackingevents',true);
$scope.setWidgetProp('3DContainer-1','dropshadow',true);
$scope.setWidgetProp('3DContainer-1','extendedtracking',true);
$scope.setWidgetProp('3DContainer-1','persistmap',true); 
console.log("now check again the setting of the envronment")
console.warn($scope.app.view.Home.wdg['3DContainer-1'].enabletrackingevents) 
var enabletrackingevets= $scope.app.view.Home.wdg['3DContainer-1'].enabletrackingevents
 if( enabletrackingevets) $scope.setWidgetProp('3DLabel-2', 'text', "3Dcontainer.enabletrackingevents=true"); 
//==================== 
$timeout($scope.setMyEYEtrack(), 2500) //call with delay 2.5 sec }); ///////////////////////////////////////////////////// 
$scope.setMyEYEtrack= function() {
 if(tml3dRenderer) 
{ try { tml3dRenderer.setupTrackingEventsCommand (function(target,eyepos,eyedir,eyeup) 
{ if (!$scope.check_if_works) 
//check if setupTrackingEvents is working fine -at least one time called { 
 $scope.check_if_works=false 
//this below make sense only for testing $scope.setWidgetProp('3DLabel-1', 'text', "callback setupTrackingEventsCommand is OK"); } 
//distance to eye 
//moved the widget in regards of the new viewpoint position of the device
$scope.setWidgetProp('label-distance-x', 'text', ($scope.app.view.Home.wdg['modelItem-1'].x -eyepos[0])); 
$scope.setWidgetProp('label-distance-y', 'text', 
 ($scope.app.view.Home.wdg['modelItem-1'].y -eyepos[1])); 
$scope.setWidgetProp('label-distance-z', 'text', ( $scope.app.view.Home.wdg['modelItem-1'].z -eyepos[2])); 
$scope.$applyAsync(); },undefined) } 
catch (e) {
$scope.setWidgetProp('3DLabel-1', 'text', "exception=");} }
else $scope.setWidgetProp('3DLabel-1', 'text', "null tml3dRenderer object on HoloLens"); 
} 
////// finish setEYEtrack

 

 

 

So in the preview you can see the distance to the modelItem coordinates system / here consider the delta Z - distance in Z direction

 

2020-02-04_17-10-04.gif

 

I need to point here again that you can find only the distance to the coordinate system (0,0,0) of   particular model widget or modelItem widget. If the widget is small sized in this case, you can suppose that this is the distance to the element with enough good accuracy. But if the modelItem/ model widget refer to  geometry which is not small - in this case  the calculated value   is the distance to coordinate system of the item and has no much sense

 

You can also check this post for an different approach to find a x,y,z postion of a point (e.g. surface) in space

Highlighted

Re: Finding distance from the model

Thank you once again @RolandRaytchev  for your continuous support.😊

But I think the code you mentioned in your post is specifically used for 3D eyewear and my project is based on mobile devices.

 

Also I am new to JS and have never used such type syntax. I would be grateful if you could attach a quick demo of the same.

Highlighted

Re: Finding distance from the model

Hi @vivekse ,

 

yes, this this is correct.  I checked it in a mobile project but it was not working stable. 

So,I tested somethings furter and have now a mobile project where it seems to work now - means you will received the coordinates of the eye positon , gaze vector and the up vector.

I tested in preview (this is only simulation for mobile device- so that the results/values are not relevant) but I tested it also on IOS Ipad6 and was working with the current Vuforia Viewver version:

 

2020-02-05_12-17-49.gif

the code :

 

function magnitute(a1,a2,a3)
{

return Math.sqrt( Math.pow(a1, 2) + Math.pow(a2, 2)+ Math.pow(a3, 2));
}

function cross(a1,a2,a3, b1,b2,b3) 
{
 return [ a2 * b3 - a3 * b2, a3 * b1 - a1 * b3, a1 * b2 - a2 * b1 ];
}
function normalizeVector(a1,a2,a3) {
    var mag = magnitute(a1,a2,a3)
    return new Vector(a1/mag, a2/mag, a3/mag);
};

/////////////////////////////////////
$rootScope.$on('modelLoaded', function() { 
 
    
   $scope.setWidgetProp('3DContainer-1','enabletrackingevents',true);
  console.log("now check again the setting of the envronment")
  console.warn($scope.app.view.Home.wdg['3DContainer-1'].enabletrackingevents)
  
  //// end of modelLoaded
});
//=============================================================
 $rootScope.$on('tracking', function( tracker,fargs  ) {
  
  console.warn(fargs.position);
 
   $scope.app.params['eyepos'] ="eyepos=("+fargs.position[0].toFixed(2)+","+fargs.position[1].toFixed(2)+","+fargs.position[2].toFixed(2)+")";
   $scope.app.params['eyedir'] ="eyedir=("+fargs.gaze[0].toFixed(2)+","+fargs.gaze[1].toFixed(2)+","+fargs.gaze[2].toFixed(2)+")";
   $scope.app.params['eyeup' ] ="eyeup =("+fargs.up[0].toFixed(2)+","+ fargs.up[1].toFixed(2)+","+fargs.up[2].toFixed(2)+")";
   var scale=1.3;
   $scope.setWidgetProp('3DImage-1',  'x', ( fargs.position[0]+fargs.gaze[0]*scale));
   $scope.setWidgetProp('3DImage-1',  'y', ( fargs.position[1]+fargs.gaze[1]*scale));
   $scope.setWidgetProp('3DImage-1',  'z', ( fargs.position[2]+fargs.gaze[2]*scale));
  //3DLabel-1 no y
   $scope.setWidgetProp('label-distance-x',  'x', ( fargs.position[0]+fargs.gaze[0]*scale)+0.0);
   $scope.setWidgetProp('label-distance-x',  'y', ( fargs.position[1]+fargs.gaze[1]*scale) -0.08*5);
   $scope.setWidgetProp('label-distance-x',  'z', ( fargs.position[2]+fargs.gaze[2]*scale));
   $scope.setWidgetProp('label-distance-y',  'x', ( fargs.position[0]+fargs.gaze[0]*scale)+0.0);
   $scope.setWidgetProp('label-distance-y',  'y', ( fargs.position[1]+fargs.gaze[1]*scale)-0.08*4);
   $scope.setWidgetProp('label-distance-y',  'z', ( fargs.position[2]+fargs.gaze[2]*scale));
   $scope.setWidgetProp('label-distance-z',  'x', ( fargs.position[0]+fargs.gaze[0]*scale)+0.0);
   $scope.setWidgetProp('label-distance-z',  'y', ( fargs.position[1]+fargs.gaze[1]*scale)-0.08*3);
   $scope.setWidgetProp('label-distance-z',  'z', ( fargs.position[2]+fargs.gaze[2]*scale));

   
   console.info("distance to 0,0,0 World CSYS = :: "+magnitute(fargs.position[0].toFixed(2),fargs.position[1].toFixed(2),fargs.position[2].toFixed(2)) )
  
 $scope.$applyAsync();
});
                            

 

In the parameter eyepos, eyedir and eyeup I created binding to the text property of the lables label-dinstance-x/y/z and are displayed there.

I attached the test project

View solution in original post

Highlighted

Re: Finding distance from the model

Thank you @RolandRaytchev . This is exeactly what I was looking for.😊

Re: Finding distance from the model

Thankyou @RolandRaytchev for your reply. I tested out as per your guideline but didn't got much success. Can you help me rectify my error. I have attached my project with this post.

Highlighted

Re: Finding distance from the model

I checked the model. I think there was a problem with the event firing.

2020-02-06_18-06-10.gif

 

so that when testing now it works. I modified it a little but it was based on the project what you did sent to me.

So, I will attach it back.  This  shows in the labels .text the event vectors and on 3d label on the bottom the distance to the 0,0,0 world coordinate / simplification / 

When testing it looks like:

2020-02-06_18-14-02.gif

 

Highlighted

Re: Finding distance from the model

I'm trying to achieve the same results as your demo, but i don't have the "Enable Tracking Events" toggle.

 

no-tracking2.JPG

 

I am using vuforia studio version 8.5.5 (8.5.5.4572)

Announcements
Topics available:
AR/VR for Data Optimization AR/VR for Security and Control AR/VR for Inspection