Ask Your Question
1

Polar to Cartesian most Elegant way ?

asked 2018-03-19 17:10:17 +0200

ortollj gravatar image

updated 2018-03-19 17:13:49 +0200

Hi

##  polar to Cartesian
forget()
# trying to get (b * x  + sqrt(x^2 + y^2)) -1= 0  from r==1/(1+b*cos(t))
# first by hand:
# sqrt(x^2 + y^2) = 1 / (b * x / sqrt(x^2 + y^2) + 1)
# sqrt(x^2 + y^2) = sqrt(x^2 + y^2) / (b * x / sqrt(x^2 + y^2) + sqrt(x^2 + y^2))
# sqrt(x^2 + y^2) = sqrt(x^2 + y^2) / (b * x  + sqrt(x^2 + y^2))
# 1 = 1 / (b * x  + sqrt(x^2 + y^2))
# (b * x  + sqrt(x^2 + y^2)) -1= 0 

# second with SageMath:

## Sagemath polar to Cartesian
forget()
t,x,y,b,r = var('t x y b r')
assume(t,'real')
#b=0.5
eq0=r==1/(1+b*cos(t))
eq1=x==r*cos(t)
eq2=y==r*sin(t)
eq3=r==sqrt(x^2 + y^2)
S=solve(eq1,cos(t))
show(S)
eq4=eq0.substitute(S[0])
eq5=eq4.substitute(eq3)
show(eq5)
eq6=(eq5.simplify_full())
eq6=(eq6/eq6.rhs().numerator())
show(eq6)
eq7=1/eq6
eqFinal=eq7-1
show(eqFinal)

is there an much elegant way to get the cartesian (b * x + sqrt(x^2 + y^2)) -1= 0 from polar r==1/(1+b*cos(t)) with sagemath (I find my Sagemath way laborious !) ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-03-19 18:25:07 +0200

eric_g gravatar image

Well, when Trac ticket #24623 will have been reviewed and merged in SageMath (maybe in version 8.2?), you will be able to do

sage: E.<x,y> = EuclideanSpace(2)
sage: cartesian = E.cartesian_coordinates()
sage: polar.<r,t> = E.polar_coordinates()
sage: R, T = E.coord_change(cartesian, polar)(x,y)
sage: R, T
(sqrt(x^2 + y^2), arctan2(y, x))
sage: b = var('b')
sage: eq0 = r==1/(1+b*cos(t))
sage: eq1 = eq0.subs({r: R, t: T})
sage: eq2 = (R/eq1).expand() - 1; eq2
0 == b*x + sqrt(x^2 + y^2) - 1

Meanwhile, you can define by hand R=sqrt(x^2+y^2) and T=arctan2(y,x) and perform the above substitutions.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2018-03-19 17:10:17 +0200

Seen: 274 times

Last updated: Mar 19 '18