- 10 Apr 2013 10:43:08 pm
- Last edited by elfprince13 on 10 Apr 2013 10:43:55 pm; edited 1 time in total

okey dokey.

added two methods for Unknown. This is probably unsafe (information destroying, not just unable to solve) for nonlinear or multivariable equations, but should fit the purpose at hand okay.

then

added two methods for Unknown. This is probably unsafe (information destroying, not just unable to solve) for nonlinear or multivariable equations, but should fit the purpose at hand okay.

**Code:**```
```

def collect_additive_terms(self,name):

if self.reciprocal:

raise ValueError("Can't collect additive terms of inverted Unknown: %s" % repr(self))

else:

usterm = type(self.sterm) == Unknown

sub_terms = self.sterm.collect_additive_terms(name) if usterm else (0,0)

return ((self.mterm if name==self.name else 0)+sub_terms[0],(0 if usterm else self.sterm)+sub_terms[1])

# not sure if this is safe with other variables...

def collapse_on(self, name):

m,s = self.collect_additive_terms(name)

return Unknown(name=name,mterm=m,sterm=s)

then

**Code:**```
lam12 = inv(T) * (Pplanar[:2]-planar[:2,2])
```

lambda1 = lam12[0,0]

lambda2 = lam12[1,0]

lambda3 = 1 - lambda1 - lambda2

rval = [lambda1,lambda2,lambda3,x,y,lambda1*trimatrix[2,0]+lambda2*trimatrix[2,1]+lambda3*trimatrix[2,2]]

rval = array([lambda1,lambda2,lambda3,x,y,z])

rval[3+c] = lambda1*trimatrix[2,0]+lambda2*trimatrix[2,1]+lambda3*trimatrix[2,2]

# feel free to put better guesses if you have them

# but it's linear so I think it should be okay?

solved = (rval[3+c] - P[2,0]).collapse_on('z')

real_z = -solved.sterm / solved.mterm

if real_z < epsilon:

unsolved_indices = array([1,2,3,3+c])

rval[unsolved_indices] = rval[unsolved_indices](z=real_z)

else:

print "Found no solution to equation %s=0" % (str(rval[3+c] - P[2,0]))

return [0., 0., 0., x, y, z]

return rval