Yes, it's a vector. Actually it's a 3d vector, the above was simplified. The sum of all components allows me to write this

- Code: Select all
`def get_sample(origin, screen, sphere):`

''' calculate vector sphere intersection '''

x1 = origin.x

y1 = origin.y

z1 = origin.z

x3 = sphere.x

y3 = sphere.y

z3 = sphere.z

r3 = sphere.r

for sample in screen.nextSample():

a = (x2 - x1)**2 + (y2 - y1)**2 + (z2 - z1)**2

b = 2 * ((x2 - x1) * (x1 - x3) + (y2 -y1) * (y1 - y3) + (z2 - z1) * (z1 - z3))

c = x3**2 + y3**2 + z3**2 + x1**2 + y1**2 + z1**2 - 2 * (x3 * x1 + y3 * y1 * z3 * z1) - r3**2

# do things with a, b and c

as this

- Code: Select all
`def get_sample(origin, screen, sphere):`

''' calculate vector sphere intersection '''

ozo = Vec3d(1, 0, 1)

for sample in screen.nextSample():

a = sum((sample - origin)**2)

b = sum(-origin ** 2) + sum(origin * sample)

+ sum(origin * sphere) + sum(-sample * sphere)

c = sum(origin ** 2) + sum(sphere ** 2) - 2 * sum( ozo * origin * sphere) - sphere.r ** 2

# do things with a, b and c

The result might not be correct (yet) as the code isn't working yet. But you are probably right that I should just define a method for this.

But apart from that, I also see examples (for making a class an iterable) that implement __iter__(), next() and something with StopIteration (can't find the link anymore :/ ). Assuming there's a legitemate case for making a class iterable, would this (__iter__(), next() and something with StopIteration) be better than using yield?

Edit: Hmm, it's a bit of a mess as I'm editing the code atm. The first code block is obviously missing the sample.x, sample.y and sample.z that should be there.