Hello,
For a project I'm currently working on, I need to draw some
parametrized shape. To achieve that I compute the complex coordinate
of each point. The problem is that some shape are quiet complex and
it's sometime hard to find the point's coordinate as a function of
our parameters. To save some time for the next shape, I want to use
SymPy to compute these coordinates. The idea would be to adapt
validated equation system to describe the new shapes. So I tried
this (simple) example :
with the following code (with the simplification P1 above P0 ie same
reel part)
#Point to find (P0 to P5 only, P6 to P10 are found by symmetry)
var("P:6", complex=True)
#Available data
H0, H1, H2, W0, W1, W2, Rbo =symbols ('H0, H1, H2, W0, W1, W2, Rbo', real=True,positive=True)
#Equation to solve
Eq_list = list()
Eq_list.append(P0 - Rbo)
Eq_list.append(P1 - P0-1j*W0/2.0)
Eq_list.append(P2 - P1 - H0)
Eq_list.append(P3 - P2 - H1-1j*(W1-W0)/2.0)
Eq_list.append(P4 -P2 - H1)
Eq_list.append(P5 - P4 -H2-1j*(W2-W0)/2.0)
result = solve (Eq_list,[P0, P1, P2, P3, P4, P5])
The result is as expected :
P0 = Rbo
P1 = Rbo + 0.5*I*W0
P2 = H0 + Rbo + 0.5*I*W0
P3 = H0 + H1 + Rbo + 0.5*I*W1
P4 = H0 + H1 + Rbo + 0.5*I*W0
P5 = H0 + H1 + H2 + Rbo + 0.5*I*W2
Now I want to remove my simplification (P1 must be on the circle, so
it's not exactly above P0). So I change my equations for P1 this way
:
Eq_list.append(Abs(P1) - Rbo)
Eq_list.append(im(P1)-im(P0)-W0/2.0)
The first equation states that P1 is on the circle of center (0,0)
and radius Rbo, and the second one that P1 is on a line parallel to
the abscissa passing by a point P0+1j*(W0/2). The expected result
is :
P1 = P0 * exp(1j*arcsin(W0/(2*Rbo)))
#Or P1 = Rbo * exp(1j*arcsin(W0/(2*Rbo)))
And I get (I'm using Python 2.7 and SymPy 0.7.6) :
NotImplementedError: solving Abs(P1) when the argument is not real or imaginary.
So the first thing I want to know is : I am doing this right ? Maybe
my problem is just due to the fact that there are two solutions for
P1 and that I need to state Re(P1) >0 (if it is possible). Or
maybe be there is a better way to solve this kind of problem with SymPy
(adding other assumption or equation, working with variables for
both real and imaginary part of each point, using another function or module I'm not knowing about...).
Anyway, having a way to specify distance and angle between some
points directly with the functions "Abs" and "arg" would be really
helpful to solve this kind of problem. So I'm wondering, how hard
would it be to implement the use of Abs and arg in your solver ? If
it's at my reach I'm ready to implement it myself (with some help
and workaround of course).
Best Regards,
Pierre Bonneel