First time here? Check out the FAQ!

Ask Your Question
1

Polar to Cartesian most Elegant way ?

asked 7 years ago

ortollj gravatar image

updated 7 years ago

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 !) ?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 7 years ago

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.

Preview: (hide)
link

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: 7 years ago

Seen: 387 times

Last updated: Mar 19 '18