Create and display local coordinate system

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
thuswm
Posts: 29
Joined: Sun May 20, 2012 11:31 am

Create and display local coordinate system

Post by thuswm »

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?
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Create and display local coordinate system

Post by jmaustpc »

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.
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Create and display local coordinate system

Post by wmayer »

Can you give us a concrete example?
thuswm
Posts: 29
Joined: Sun May 20, 2012 11:31 am

Re: Create and display local coordinate system

Post by thuswm »

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?
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Create and display local coordinate system

Post by wmayer »

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.
thuswm
Posts: 29
Joined: Sun May 20, 2012 11:31 am

Re: Create and display local coordinate system

Post by thuswm »

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?
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Create and display local coordinate system

Post by wmayer »

I'm quite familiar with local coordinate systems too because I'm working also a lot with them.
Many times the user (or at least I) wants the inertia to be calculated with respect to a different set of axes or origin.
So, that's exactly what I wanted to know. :)

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.
thuswm
Posts: 29
Joined: Sun May 20, 2012 11:31 am

Re: Create and display local coordinate system

Post by thuswm »

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:

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;
}
...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.
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Create and display local coordinate system

Post by wmayer »

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...
Actually, I am not looking for the coordinate system to do the calculations automatically
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.

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.
User avatar
jriegel
Founder
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: Create and display local coordinate system

Post by jriegel »

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...
Stop whining - start coding!
Post Reply