Create and display local coordinate system
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Create and display local coordinate system
I am implementing a function for calculating mass properties for solids (CoG and Moment of Inertia). I do this since I would need a simple Gui for that and I also thought it would be a perfect way to learn the FreeCAD python interface. The first couple of steps have been fairly straight forward (with some help from the forum).
For the next step I would like to be able to specify a local coordinate system for which these properties are calculated (transformed from the global coordinate system). My problem is that I cannot find any way to create a local coordinate system. Is there a method for that?
Also, is it possible to display this coordinate system with three axes so that it is possible to select it?
For the next step I would like to be able to specify a local coordinate system for which these properties are calculated (transformed from the global coordinate system). My problem is that I cannot find any way to create a local coordinate system. Is there a method for that?
Also, is it possible to display this coordinate system with three axes so that it is possible to select it?
Re: Create and display local coordinate system
thuswm wrote:I am implementing a function for calculating mass properties for solids (CoG and Moment of Inertia). I do this since I would need a simple Gui for that and I also thought it would be a perfect way to learn the FreeCAD python interface. The first couple of steps have been fairly straight forward (with some help from the forum).
For the next step I would like to be able to specify a local coordinate system for which these properties are calculated (transformed from the global coordinate system). My problem is that I cannot find any way to create a local coordinate system. Is there a method for that?
Also, is it possible to display this coordinate system with three axes so that it is possible to select it?
Juergen said the other day that when he's ready he'll be dumping his Assembly stuff into 0.14 and then will end development of 0.13. I don't think this is very far of now. If I am understanding correctly, (which I may not be) Juergen is making some invasive changes that will affect the coordinate system. It might be a good idea to discuss your plans for your tool with him if you want your tool to be functional in the long term.
I don't don't have enough knowlege to answer your question properly.
Re: Create and display local coordinate system
Can you give us a concrete example?
Re: Create and display local coordinate system
wmayer: Is it the code you are asking for or should I give an example of how I would like the next step in my script to work?
Re: Create and display local coordinate system
Neither the one nor the other. You're talking about creating a local coordinate system but for me it's not quite clear what you want to do with it.
Re: Create and display local coordinate system
I come from the Finite Element world and there local coordinate systems are extremely convenient and used a lot. I know that e.g. CATIA also has this possibility so I guess that Mechanical 3D modelling also uses them.
When I say "local coordinate system" (you may possibly use a different nomenclature) I mean that the user can define a coordinate system that is related to the global coordinate system. You e.g. specify that the local coordinate system should have a specific origin located at point [x,y,z] relative to the global. It is also common that the axes of the local coordinate system are rotated compared to the global. In some FE tools it is also possible to define these new local systems as cylindrical or spherical but I think that is a much later issue here.
Now, when FreeCAD calculates the matrix of inertia this is done with the reference to the global system and with the centre of gravity (CoG) as the origin. Many times the user (or at least I) wants the inertia to be calculated with respect to a different set of axes or origin. In this case it would be nice if the user could define a local coordinate system (or as many as he/she wishes) and then when requesting the inertia calculation the user may choose this system.
Therefore, it should not only be possible to create these systems but also they should be visible, selectable objects.
Is it more clear now or did I manage to confuse you even more?
When I say "local coordinate system" (you may possibly use a different nomenclature) I mean that the user can define a coordinate system that is related to the global coordinate system. You e.g. specify that the local coordinate system should have a specific origin located at point [x,y,z] relative to the global. It is also common that the axes of the local coordinate system are rotated compared to the global. In some FE tools it is also possible to define these new local systems as cylindrical or spherical but I think that is a much later issue here.
Now, when FreeCAD calculates the matrix of inertia this is done with the reference to the global system and with the centre of gravity (CoG) as the origin. Many times the user (or at least I) wants the inertia to be calculated with respect to a different set of axes or origin. In this case it would be nice if the user could define a local coordinate system (or as many as he/she wishes) and then when requesting the inertia calculation the user may choose this system.
Therefore, it should not only be possible to create these systems but also they should be visible, selectable objects.
Is it more clear now or did I manage to confuse you even more?
Re: Create and display local coordinate system
I'm quite familiar with local coordinate systems too because I'm working also a lot with them.
In FreeCAD we have so called placements which is a rotation (expressed as a quaternion) and a translation vector. This placement is synchronized with the location information of the TopoDS_Shape object. So, if you want to compute the matrix of inertia you first have to make a copy of you original shape, modify the Placement attribute accordingly and then do the actual computation.
Unfortunately, we currently have no coordinate system object which could do this stuff automatically.
Since jriegel is working on the assembly module which seems to have certain overlaps with your requests it might be best to contact him directly.
So, that's exactly what I wanted to know.Many times the user (or at least I) wants the inertia to be calculated with respect to a different set of axes or origin.
In FreeCAD we have so called placements which is a rotation (expressed as a quaternion) and a translation vector. This placement is synchronized with the location information of the TopoDS_Shape object. So, if you want to compute the matrix of inertia you first have to make a copy of you original shape, modify the Placement attribute accordingly and then do the actual computation.
Unfortunately, we currently have no coordinate system object which could do this stuff automatically.
Since jriegel is working on the assembly module which seems to have certain overlaps with your requests it might be best to contact him directly.
Re: Create and display local coordinate system
Actually, I am not looking for the coordinate system to do the calculations automatically. I would just like to be able to create coordinate system objects (that are visible and selectable). From these objects I would then get the relevant information for the inertia matrix transformation. The math is the easy part. It's the FreeCAD interface I'm trying to learn!
Pseudo code for the object interface could look something like this:
...just an idea...
I believe that I understand the method you suggest but it will not give me the functionality (for the end user) that I am looking for. Unfortunately I know too little about the FreeCAD implementation to be able to create this coordinate system object. In my mind it should be quite straight forward but, there are always some implications of new objects that are difficult to foresee. Is there an example of how to implement new objects (visible and selectable) somewhere? I could give it a try...
Thank you for your help! I hope I did not sound condescending...I was only trying to be as clear as possible.
Pseudo code for the object interface could look something like this:
Code: Select all
class CoordSys
{
public:
CoordSys( name, refSys, origin, rotation); // more constructors for convenient creation will be needed
getTransformation();
transformToGlobal(x,y,z); // translate the local coordinates to global; To be sued as input for FreeCAD functions
setVisible(bool); // turn visibility on/off
private:
Name;
TransformationMatrix;
}
I believe that I understand the method you suggest but it will not give me the functionality (for the end user) that I am looking for. Unfortunately I know too little about the FreeCAD implementation to be able to create this coordinate system object. In my mind it should be quite straight forward but, there are always some implications of new objects that are difficult to foresee. Is there an example of how to implement new objects (visible and selectable) somewhere? I could give it a try...
Thank you for your help! I hope I did not sound condescending...I was only trying to be as clear as possible.
Re: Create and display local coordinate system
No problem!
But anyway since jriegel is working on the assembly module he has implemented something like a coordinate system object, for sure. I'll ask him...
The way to add new objects is to:
1.
* Make a sub-class of App::DocumentObject (or sub-class of it).
* Add the needed properties to the new class
* Override the execute() method and/or mustExecute()
2. Make a view provider for it by sub-classing Gui::ViewProviderDocumentObject
... (too lazy to look what needs to be done exactly)
Btw it's also possible to extend FreeCAD with those object written in Python. But in this case it makes most sense to have this in C++ directly.
But anyway since jriegel is working on the assembly module he has implemented something like a coordinate system object, for sure. I'll ask him...
I didn't mean to compute the matrix of inertia but applying the placement. Nevertheless I'll first contact jriegel and discuss this with him.Actually, I am not looking for the coordinate system to do the calculations automatically
The way to add new objects is to:
1.
* Make a sub-class of App::DocumentObject (or sub-class of it).
* Add the needed properties to the new class
* Override the execute() method and/or mustExecute()
2. Make a view provider for it by sub-classing Gui::ViewProviderDocumentObject
... (too lazy to look what needs to be done exactly)
Btw it's also possible to extend FreeCAD with those object written in Python. But in this case it makes most sense to have this in C++ directly.
Re: Create and display local coordinate system
Actually Werner is right, this objects already in the Assembly branch and slectably.
In some weeks I will merge this branch into the master and this objects will appear in the
the unstable releases...
In some weeks I will merge this branch into the master and this objects will appear in the
the unstable releases...
Stop whining - start coding!