Page 1 of 2

How to change local coordinates to global coordinates

Posted: Fri Jun 09, 2017 7:13 am
by yyuan
Hello,

Is there a function to change a merker's local coordinate(-0.0461907 -0.0591856 -0.037296 for example) to its global coordinate (1.166667e+00 9.327390e+00 8.491460e+02 for example)?

Thanks a lot!

Re: How to change local coordinates to global coordinates

Posted: Fri Jun 09, 2017 3:00 pm
by tkuchida
In the GUI, select the Marker in the Navigator and change the value of its "body" property to "ground"; the value of its "location" property will be transformed from local coordinates into the global frame. (After changing the value of the "body" property, you need to click on another property for the "location" property to update.)

Re: How to change local coordinates to global coordinates

Posted: Mon Jun 12, 2017 1:17 am
by yyuan
Thank you!
In fact, my question is, in the c++ code, is there a function to transform local coordinates to global coordinates or conversely?

Re: How to change local coordinates to global coordinates

Posted: Mon Jun 12, 2017 1:18 am
by yyuan
tkuchida wrote:In the GUI, select the Marker in the Navigator and change the value of its "body" property to "ground"; the value of its "location" property will be transformed from local coordinates into the global frame. (After changing the value of the "body" property, you need to click on another property for the "location" property to update.)
Thank you!
In fact, my question is, in the c++ code, is there a function to transform local coordinates to global coordinates or conversely?

Re: How to change local coordinates to global coordinates

Posted: Mon Jun 12, 2017 1:24 am
by tkuchida
in the c++ code, is there a function to transform local coordinates to global coordinates or conversely?
Yes, you can use the transformPosition() method (https://simtk.org/api_docs/opensim/api_ ... 36ab374330). A script that uses this method can be found in the last post on the first page of this thread: viewtopicPhpbb.php?f=91&t=7723.

Re: How to change local coordinates to global coordinates

Posted: Mon Jun 12, 2017 1:28 am
by mitkof6
Hi,

You can transform a station defined in body "From" to a location define in body "To" (in your case its the ground body).

https://simtk.org/api_docs/opensim/api_ ... 35205654c6

Best

Re: How to change local coordinates to global coordinates

Posted: Mon Jun 12, 2017 6:47 am
by yyuan
tkuchida wrote:
in the c++ code, is there a function to transform local coordinates to global coordinates or conversely?
Yes, you can use the transformPosition() method (https://simtk.org/api_docs/opensim/api_ ... 36ab374330). A script that uses this method can be found in the last post on the first page of this thread: viewtopicPhpbb.php?f=91&t=7723.
When I applied the function "_model->getSimbodyEngine().transformPosition(s, fromBody, marker_1_pos, toBody, newLoc);", it says that

> SimTKsimbody.dll!SimTK::SimbodyMatterSubsystem::getMobilizedBody(SimTK::MobilizedBodyIndex id) Ligne 90 C++
osimSimulation.dll!OpenSim::SimbodyEngine::transformPosition(const SimTK::State & s, const OpenSim::Body & aBodyFrom, const SimTK::Vec<3,double,1> & aPos, const OpenSim::Body & aBodyTo, SimTK::Vec<3,double,1> & rPos) Ligne 486 C++

Can you explain why? I followed your example but still don't know why it doesn't work.
Thanks

Re: How to change local coordinates to global coordinates

Posted: Mon Jun 12, 2017 12:29 pm
by tkuchida
Can you explain why?
No, not with the information provided. Is there an error message? What version of OpenSim are you using? Have you confirmed that MATLAB has been configured correctly; do other scripts run?

Re: How to change local coordinates to global coordinates

Posted: Tue Jun 13, 2017 5:00 am
by yyuan
I'm using opensim 3.3, it seems that the problem is the programme cannot get the right body, with following code:
Body fromBody,toBody;
bs = _model->getBodySet();
for (i = 0; i < bs.getSize(); i++){
if (bs.getName() == "scapula"){
fromBody = bs;
cout << "fromBody found!!!" << endl;
}
else if (bs.getName() == "ground"){
toBody = bs;
cout << "toBody found!!!" << endl;
}
}
double distance = _model->getSimbodyEngine().calcDistance(s, fromBody, markerset[1].getOffset(), toBody, markerset[2].getOffset());

I noticed that toBody.getIndex() and fromBody.getIndex() will return -1111111111,
Writting these in InverseKinematicTool.cpp, methode run(),
The error message is :
Exception de première chance à 0x00CE75FB (SimTKsimbody.dll) dans Ellipsoide.exe : 0xC0000005 : Violation d'accès lors de la lecture de l'emplacement 0xF8BAE66C.
Exception non gérée à 0x00CE75FB (SimTKsimbody.dll) dans Ellipsoide.exe : 0xC0000005 : Violation d'accès lors de la lecture de l'emplacement 0xF8BAE66C.
After google translation:
First chance exception to 0x00CE75FB (SimTKsimbody.dll) in Ellipsoide.exe: 0xC0000005: Access violation when reading the 0xF8BAE66C location.
Unhandled exception to 0x00CE75FB (SimTKsimbody.dll) in Ellipsoide.exe: 0xC0000005: Access violation when reading the 0xF8BAE66C location.
I tried your way to get a Body: toBodyName = 'r_humerus';toBody = model.getBodySet().get(toBodyName); doesn't work either.
Is that detailed enough? BTW I'm not using MATLAB but VS2013, thank you!

Re: How to change local coordinates to global coordinates

Posted: Tue Jun 13, 2017 5:03 am
by yyuan
mitkof6 wrote:Hi,

You can transform a station defined in body "From" to a location define in body "To" (in your case its the ground body).

https://simtk.org/api_docs/opensim/api_ ... 35205654c6

Best
Thank you!
BTW are you able to solve my problem?