[solved] Polar Coordinates Scripting

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
blusser

[solved] Polar Coordinates Scripting

Post by blusser »

Hi,
is it possible to start Scripting in a polar coordinate system?
I haven't found anything regarding this and i haven't found anything regarding Freecad.vectors?
I want to move stuff in a polar coordinate system by scripting. I would also like return values of polar stuff.
I could convert it, but i have a time critical application.

cheers
blusser
Last edited by blusser on Sat Jul 16, 2022 8:58 am, edited 1 time in total.
User avatar
onekk
Veteran
Posts: 6205
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Polar Coordinates Scripting

Post by onekk »

Polar coordinate are not used by FC as internally the 3d engine will use quaternions (for rotation and translation) and vectors3d.

Maybe there are ways of using polar coordinates in FC but with scripting you are working "very near" to the OCCT core so you have to supply data in a format that is used.

Probably there are methods around to specify "polar cordinate" and obtain data compatible with placement data (Translation vector and rotation).

Something similar to this:

https://github.com/FreeCAD/FreeCAD-macr ... ar.FCMacro


Regards

Carlo D.
Last edited by onekk on Thu Jul 14, 2022 8:09 pm, edited 1 time in total.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
edwilliams16
Veteran
Posts: 3179
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Polar Coordinates Scripting

Post by edwilliams16 »

2D polar, 3D spherical polar, 3D cylindrical polar?

There are some methods exposed in the API you could use, but it would be less clumsy to write your own. Use numpy if you need to parallelize operations for speed, for instance the following avoids looping the interpreter over the coordinate list.

Code: Select all

import numpy as np
def cart2polar(xy):
    pts = np.zeros(xy.shape)
    pts[:,0] = np.hypot(xy[:,1], xy[:,0])
    pts[:,1] = np.arctan2(xy[:,1], xy[:,0])
    return pts

arr = np.array([[1,1],[2,2],[0,1]])
cart2polar(arr)   #array([[1.41421356, 0.78539816], [2.82842712, 0.78539816], [1.        , 1.57079633]])
https://wiki.freecadweb.org/Vector_API
App.Base.Vector2d for 2d vectors
blusser

Re: [solved] Polar Coordinates Scripting

Post by blusser »

All right. Thanks for your tipps.
User avatar
mfro
Posts: 666
Joined: Sat Sep 23, 2017 8:15 am

Re: [solved] Polar Coordinates Scripting

Post by mfro »

blusser wrote: Thu Jul 14, 2022 8:54 am I could convert it, but i have a time critical application.
Even if theFreeCAD OCC glue had such methods you are looking for, it would still be required to remap polar coordinates into cartesian (since that it what OCC expects), so probably no performance increase it they were there anyway.
Cheers,
Markus
Post Reply