trigonometry

Why does math.cos(math.pi/2) not return zero?

Why does math.cos(math.pi/2) not return zero? Question: I came across some weird behavior by math.cos() (Python 3.11.0): >>> import math >>> math.cos(math.pi) # expected to get -1 -1.0 >>> math.cos(math.pi/2) # expected to get 0 6.123233995736766e-17 I suspect that floating point math might play a role in this, but I’m not sure how. And if …

Total answers: 3

Drawing an arc tangent to two lines segments in Python

Drawing an arc tangent to two lines segments in Python Question: I’m trying to draw an arc of n number of steps between two points so that I can bevel a 2D shape. This image illustrates what I’m looking to create (the blue arc) and how I’m trying to go about it: move by the …

Total answers: 2

Drawing an ellipse at an angle between two points in Python

Drawing an ellipse at an angle between two points in Python Question: I’m trying to draw an ellipse between two points. So far, I have it mostly working: The issue comes with setting the ellipse height (ellipse_h below). x = center_x + radius*np.cos(theta+deg) y = center_y – ellipse_h * radius*np.sin(theta+deg) In this example, it’s set …

Total answers: 1

Expand sin(acot(…)) in sympy?

Expand sin(acot(…)) in sympy? Question: Is there a way to expand the trigonometric function of an inverse trigonometric function? I have a long-expression f that contains many such subexpressions, e.g.: sin(0.5 acot(x))**2 cos(0.5 acot(x))**2 sin(acot(x)) These expressions can be rewritten without trigonometric functions, e.g.: 1/2 – 1/2 * x / sp.sqrt(x**2 + 1) I’ve tried …

Total answers: 1

Find angle from triangle in python (Similar to using sin-1 on scientific calculators)?

Find angle from triangle in python (Similar to using sin-1 on scientific calculators)? Question: I want to find the angle from a triangle in Python. I searched other topics here but none of them helped me… My code: from math import hypot, sin opposite = 5 adjacent = 8.66 hypotenuse= hypot(opposite, adjacent) # Trigonometry – …

Total answers: 1

SymPy returns no solution for a simple set of trigonometric equations

SymPy returns no solution for a simple set of trigonometric equations Question: I’m trying to solve the following equations: cos(a) – cos(b) – 1 = 0 and sin(a) – sin(b) = 0 Using SymPy I get no solutions for (a,b). from sympy import symbols, sin, cos, solve, Eq a, b = symbols("a b") eq1 = …

Total answers: 2

numpy.sin function in degrees?

numpy.sin function in degrees? Question: I’m working on a problem that has to do with calculating angles of refraction and what not. However, it seems that I’m unable to use the numpy.sin() function in degrees. I have tried to use numpy.degrees() and numpy.rad2deg(). numpy.sin(90) numpy.degrees(numpy.sin(90)) Both return ~ 0.894 and ~ 51.2 respectively. Thanks for …

Total answers: 5

How to calculate the angle between a line and the horizontal axis?

How to calculate the angle between a line and the horizontal axis? Question: In a programming language (Python, C#, etc) I need to determine how to calculate the angle between a line and the horizontal axis? I think an image describes best what I want: Given (P1x,P1y) and (P2x,P2y) what is the best way to …

Total answers: 9

Inverse Cosine in Python

Inverse Cosine in Python Question: Apologies if this is straight forward, but I have not found any help in the python manual or google. I am trying to find the inverse cosine for a value using python. i.e. cos⁻¹(x) Does anyone know how to do this? Thanks Asked By: Sheik Yerbouti || Source Answers: We …

Total answers: 7