Another approach to assembly solver (A2plus)

Discussion about the development of the Assembly workbench.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Jee-Bee
Veteran
Posts: 2566
Joined: Tue Jun 16, 2015 10:32 am
Location: Netherlands

Re: Another approach to assembly solver (A2plus)

Post by Jee-Bee »

kbwbe wrote: Sun Jul 29, 2018 11:02 amHi @JeeBee,

i am not really firm to use numpy. Therefore i decided for myself to use FreeCAD's API functions in hope, that they are fast enough as coded in C.

Do you expect a big difference in calculation speed using numpy instead of FreeCAD's API ?
I didn't know freecad has it's own api. I expected the default python math package.
And I know from that one that is not optimised for vectors...
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (A2plus)

Post by kbwbe »

Jee-Bee wrote: Sun Jul 29, 2018 1:47 pm
kbwbe wrote: Sun Jul 29, 2018 11:02 amHi @JeeBee,

i am not really firm to use numpy. Therefore i decided for myself to use FreeCAD's API functions in hope, that they are fast enough as coded in C.

Do you expect a big difference in calculation speed using numpy instead of FreeCAD's API ?
I didn't know freecad has it's own api. I expected the default python math package.
And I know from that one that is not optimised for vectors...
From python math module i am using only few things. (math.pi, math.sqrt() ) at uncritical points regarding speed.
Most things are done via FreeCAD's vector-api and placement-api. Everything what's needed for solving exists there...
KBWBE

https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
project4
Posts: 237
Joined: Fri Jul 12, 2013 12:53 pm

Re: Another approach to assembly solver (A2plus)

Post by project4 »

Turro75 wrote: Sun Jul 29, 2018 7:28 am Substract spincenter to both v1 and v2, now you have two vectors which are both starting at origin and keep original angle. So now getangle gives you a reliable value.

As Kbwbe already said be careful on using methods on spincenter as most of them modify spincenter too
@kbwbe, @Turro75

Guys,
It looks like Vector.getAngle returns absolute angle without the rotation direction.
I would expect to see opposite numbers if I call "v1.getAngle(v2)" and "v2.getAngle(v1)".

For example, for that case, where bottom bars are fixed and I sum all the angles, I would expect to see zero sum:
4.png
4.png (4.78 KiB) Viewed 1135 times
Any tips how I can get rotation angle with rotation direction?
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (A2plus)

Post by kbwbe »

project4 wrote: Sun Jul 29, 2018 2:53 pm
Turro75 wrote: Sun Jul 29, 2018 7:28 am Substract spincenter to both v1 and v2, now you have two vectors which are both starting at origin and keep original angle. So now getangle gives you a reliable value.

As Kbwbe already said be careful on using methods on spincenter as most of them modify spincenter too
@kbwbe, @Turro75

Guys,
It looks like Vector.getAngle returns absolute angle without the rotation direction.
I would expect to see opposite numbers if I call "v1.getAngle(v2)" and "v2.getAngle(v1)".

For example, for that case, where bottom bars are fixed and I sum all the angles, I would expect to see zero sum:
4.png

Any tips how I can get rotation angle with rotation direction?
Hi @project4,
this is correct. vector1.getAngle(vector2) returns absolute angle. Therefore i always calculate the cross-product of the vectors before that.
The direction of the resulting vector depends on order creating it. vec1.cross(vec2) != vec2.cross(vec1), they are opposed vectors.

vec1.cross(vec2).normalize().multiply(angle) has always information about rotation direction.
If you add two spins from your example above, resulting spin is zero, as expected...
KBWBE

https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
Turro75
Posts: 179
Joined: Mon Aug 15, 2016 10:23 pm

Re: Another approach to assembly solver (A2plus)

Post by Turro75 »

Try playing with vector.dot(vector)

this what it does

def dotproduct(first, other):
"dotproduct(Vector,Vector) - returns the dot product of both vectors"
if isinstance(first,FreeCAD.Vector) and isinstance(other,FreeCAD.Vector):
return (first.x*other.x + first.y*other.y + first.z*other.z)

def angle(first, other=FreeCAD.Vector(1,0,0)):
"angle(Vector,Vector) - returns the angle in radians between the two vectors.
If only one is given, angle is between the vector and the horizontal East direction"
if isinstance(first,FreeCAD.Vector) and isinstance(other,FreeCAD.Vector):
return math.acos(dotproduct(normalized(first),normalized(other)))

this is taken from here

https://www.freecadweb.org/wiki/FreeCAD ... th_library
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (A2plus)

Post by kbwbe »

Turro75 wrote: Sun Jul 29, 2018 3:29 pm Try playing with vector.dot(vector)

this what it does

def dotproduct(first, other):
"dotproduct(Vector,Vector) - returns the dot product of both vectors"
if isinstance(first,FreeCAD.Vector) and isinstance(other,FreeCAD.Vector):
return (first.x*other.x + first.y*other.y + first.z*other.z)

def angle(first, other=FreeCAD.Vector(1,0,0)):
"angle(Vector,Vector) - returns the angle in radians between the two vectors.
If only one is given, angle is between the vector and the horizontal East direction"
if isinstance(first,FreeCAD.Vector) and isinstance(other,FreeCAD.Vector):
return math.acos(dotproduct(normalized(first),normalized(other)))

this is taken from here

https://www.freecadweb.org/wiki/FreeCAD ... th_library
Hi @Turro75,
please do not use "DraftVecUtils". There is to much python inside. It seems to be slow. I hope that FreeCAD's vector api is not using it.
KBWBE

https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
Turro75
Posts: 179
Joined: Mon Aug 15, 2016 10:23 pm

Re: Another approach to assembly solver (A2plus)

Post by Turro75 »

it was just to know what dot product does and how it find positive or negative angles.

Don't worry, there is no need to use DraftVecUtils
User avatar
manuelkrause
Posts: 442
Joined: Thu Jul 05, 2018 7:16 pm

Re: Another approach to assembly solver (A2plus)

Post by manuelkrause »

kbwbe wrote: Sun Jul 29, 2018 1:40 pm Hi @project4,@turro75,@manuelkrause,

Branch "solver-stabilization" has been updated again.
There is a new command "repair-treeview". After deleting an imported part and further undoing this by FreeCAD, the constraints were not grouped under the import parts any more. By using "repair-treeview" they are sorted again to correct place.

I do not know how to start this automatically after "undo", therefore a new command at moment.
@project4: Do you know how to start the "repair-treeview" after undo automatically ?
Hi @kbwbe, @project4 and @turro75 !

It's really nice to see and read how you continuously improve this valuable WB A2plus! :D
For some unknown reason I haven't ever stumbled over this issue (either never needed to undo in this way, or not believed that the constraints get recovered, too, by this undo operation). Good to have a recovery function for this case, anyway. Needless to repeat, that an automatic reaction of A2plus upon such undo is highly appreciated... ;-)

Keep up your great work, and please never let this easy-to-use assembly facility for FreeCAD vanish (again) !

Manuel
project4
Posts: 237
Joined: Fri Jul 12, 2013 12:53 pm

Re: Another approach to assembly solver (A2plus)

Post by project4 »

kbwbe wrote: Sun Jul 29, 2018 3:52 pm
Turro75 wrote: Sun Jul 29, 2018 3:29 pm Try playing with vector.dot(vector)

this what it does

def dotproduct(first, other):
"dotproduct(Vector,Vector) - returns the dot product of both vectors"
if isinstance(first,FreeCAD.Vector) and isinstance(other,FreeCAD.Vector):
return (first.x*other.x + first.y*other.y + first.z*other.z)

def angle(first, other=FreeCAD.Vector(1,0,0)):
"angle(Vector,Vector) - returns the angle in radians between the two vectors.
If only one is given, angle is between the vector and the horizontal East direction"
if isinstance(first,FreeCAD.Vector) and isinstance(other,FreeCAD.Vector):
return math.acos(dotproduct(normalized(first),normalized(other)))

this is taken from here

https://www.freecadweb.org/wiki/FreeCAD ... th_library
Hi @Turro75,
please do not use "DraftVecUtils". There is to much python inside. It seems to be slow. I hope that FreeCAD's vector api is not using it.
Ok. Based on the printouts now I have the needed rotation center and the rotation angle...
How do I apply it to the rigid.spin?

I should probably get somehow the rotation axis... how do I do it?

@kbwbe, @Turro75
Your math lessons are needed again :)
Turro75
Posts: 179
Joined: Mon Aug 15, 2016 10:23 pm

Re: Another approach to assembly solver (A2plus)

Post by Turro75 »

Guys,

this was a thought Sunday, let's see what it turned out, the first library to handle DOF...

I wrote it as a library so You can easily insert it in the code by Yourself

I detailed as much as I can in the file, it should be self-explained anyway let me know for any further info
Attachments
DOF_Management.py
(19.33 KiB) Downloaded 40 times
Post Reply