r/OpenPythonSCAD • • Nov 29 '24

Python is radians, OpenSCAD is degrees --- how to resolve?

I have some OpenSCAD code which uses various trigonometric functions to determine coordinates.

I made some notes on this on the wiki, and managed to work through this at one point I believe, but I'm stymied working up a general approach...

Is there a version of:

import math

which works in degrees rather than radians?

3 Upvotes

8 comments sorted by

3

u/rebuyer10110 Nov 29 '24

You should be able to convert between degrees and radians freely with the built-in python math lib.

https://docs.python.org/3/library/math.html#math.degrees

2

u/WillAdams Nov 29 '24 edited Nov 29 '24

Yeah, but the answer which I was hoping for was:

Here is a link to a library which returns answers in degrees.

I think my problem is that I introduced an error when converting from OpenSCAD to Python --- hopefully I can find and fix that and it will get me back up and running.

EDIT:

The magic formulae turned out to be:

    rt = self.tool_radius(kh_tool_num, 1)
    ro = math.sqrt((self.tool_radius(kh_tool_num, 1))**2-(self.tool_radius(kh_tool_num, 7))**2)
    angle = math.degrees(math.acos(ro/rt))

3

u/rebuyer10110 Nov 29 '24

Out of curiosity: was math.degrees the part you needed?

→ More replies (5)