Friday, July 29, 2005

IT WORKS!!!!!!!

Ford came over today and we looked at my code. He thought the problem might be that I was setting the length of each number to 4 bytes, so he wrote a quick program in C++ that would read in my binary file and display the numbers in ASCII. So he tests it a bit and then pulls up a list of numbers and asks "are these the radii of the cells?"

Oops. Turns out there is not just one number for the radii at the beginning. There is supposed to be one radius for each cell. And then the list of coordinates starts.

I am happy for several reasons:
It was an easy problem to fix.
I was right--it was reading in the wrong numbers for the wrong things. Kind of like a frame shift, but not as bad of one as I was thinking it might be.
I now have a program that will display my binary file in ASCII with markers for when the radii start, when the x y z coordinates start and when each timestep begins.

Once I added that list of radii it worked great, and then I put in a conversion so that my x y z coordinates show up correctly on the SimRender coordinates. So the hostcells now show up on the "floor" and parasites bounce around properly. Here's what it looks like now:


Yellow are host cells, red with green vectors are parasites. The green brackets are just selecting that cell.

There is only one problem. For some reason, the right hand wall is sticky. All the parasites hit it, or even end up outside it some how, and stick. Because of the way the world is set up, that wall is actually controlled by y-minimum in my code. So for some reason when a parasite's y-coordinate is less than or equal to 5 (y<= 5), the velocity turns to zero. This does not happen on any of the other walls. I checked the code and I can't find anything different about y-min...

very odd.

Thursday, July 28, 2005

Frame Shift?

What I wouldn't give for an extremely detail oriented person right now...

It should be simple. Give SimRender this list of numbers, and it will display the parasites moving according to those numbers. I tried to follow what Ford gave as the format exactly. But SimRender is not reading the file properly. It's almost like... a frame shift. If I were to give an example of what I think is happening: Say I give it

10 20.432 30 40 50 60

And then it reads that as:

102 0.4 32 30 405 0 60

But it isn't a pattern that I can look at and say, oh, this is what is wrong. Maybe it is different because it's converted to binary first and there are extra bits or bytes or words or THINGIES that tell it whether it is signed or not.

I need to know EXACTLY what SimRender is, taking NOTHING for granted. Things that are default in C++ have to be manually set in Scheme.

As it is I'm going to have to make up some kind of formula to switch x y z coordinates to the coordinate system that SimRender uses (he swapped the y and z axis, and the origin is in the back lower right corner instead of the back lower left corner).

[vent] I hate not having all my ducks in a row like this. In order to make this work I need to know where all the pieces are and how they fit. And I don't. SO frustrating. And there are only about 10 days till I have to give my presentation. And there is more to do beyond just getting it to display. ARRRGH. [/vent]

Wednesday, July 27, 2005

SO close...

I'm torn between doing cartwheels and crying in frustration.

My Scheme program outputs what I think are the right numbers in the right order in the right format to the right file. AND SimRender finally will open it!!!!! YAY!!! That's the cartwheels part.

However, SimRender is not supposed to take what I gave it and display this:


The spheres are supposed to all be pretty tiny. Instead they are all different sizes from huge to small, a lot of them are outside the world (you can barely see the wire frame box in upper left part of the screen shot), and I'm not sure they are moving correctly. Sighs.... AND I don't know what's wrong. That's the cry in frustration part.

Thanks to Kyle for help with getting SimRender working, Michael for help with linux, and Dr. Iba for help with Scheme and binary.

Tuesday, July 26, 2005

got the right tools now...

With Dr. Iba's help I added some functions to my repetouir today. Now I should be able to write output to a file, and change floating points and integers into binary.

First though I need to write a function that will return the right set of numbers. I can map the update-cell function onto the swarm a given number of times pretty easily, but getting the right numbers to all come out after each recursion is a little more tricky. I can use (print ...), but I'm not sure that will work with the whole output thing. Here I go again, trying to make something work that I know almost nothing about, lol.

I seriously need to have this working by the end of the week though. And I still have to go get SimRender, and get it compiled and working so I can give it the output file to chew on. I hope that SimRender doesn't freak out when parasites try to pass through each other. Because they are going to. I don't have anything in the program to make them avoid each other.

Monday, July 25, 2005

hurdles

Tarynn is back :-)

The calculations work the way they are supposed to (woot!). But I'm still a ways away from getting it to display on SimRender though. What remains aren't so much walls as hurdles. Be prepared for a fairly large e-mail Dr. Iba....

--I need to write a piece of code that prints out a list of numbers into a file. Shouldn't be hard, just haven't done it before.
--That file must be in binary. I'm assuming Scheme can do this... I hope.
--I'm pretty sure that in order to print in binary I'll need to be running a language bigger than "Advanced Student". "Pretty Big" looks good because it has all the stuff of Advanced Student and MrEd (which includes MzScheme, which includes the standard language). I'm running into problems when I try to switch to Pretty Big though. It's throwing an error that I don't understand, and quite frankly, DrScheme's documentation stinks. There maybe be more problems beyond that, but I won't know until I fix the first problem. I did find out how to fix the format of the vectors so that it accepted them. Annoying that the student languages are so different from regular Scheme.

And now a bit of fun: PhD (Piled Higher and Deeper)
Well worth reading the entire archive.
And yes, I have.

Friday, July 22, 2005

sticky corners and edges

I wonder who is hitting more walls: me, or the paranoids. The code pretty much works, except I found out that it isn't the walls that are sticky--it's the edges and corners. I've tried tweaking the code, to no avail. I'm going to need to rework a fairly large piece of it. The problem is that I don't exactly know how I want it to do what I need it to do.

If the paranoid is on one wall, then I check the coordinates to find which wall and set the normal vector accordingly. But if it is on an edge, then it is essentially on two walls at once. And if it is on a corner, then it is on three walls at once. What needs to happen is for the vector update function to run for each wall, using the resulting vector from the previous wall as the vector for the next wall. For example, say the paranoid is sitting on walls x, y, and z. Its coordinates would be (x, y, z). The function would need to look at the x and update the vector (V) to V'. Then, the function would need to look at y and update V' to V''. Then the function would need to look at z and update V'' to V'''. If the critter was only on walls x and z, (x, n, z) then the function would need to look at x and update it from V to V', then look at n and see that it is ok, then look at z and update it from V' to V''.

I'm going to need some kind of recursive thing. You know what is really funny? I'm spending so much time on something that the parasites don't even do. sigh. It's certainly good practice though, and it needs to be done so that the program can work until what they really do can be programmed in.

I also need to figure out how I can get the set of functions to repeat through a list a given number of times.

This all could take quite a while. Two work-weeks left. And a presentation on this that needs writing.

Thursday, July 21, 2005

working, but with sticky walls

Whew. I got all of the functions for bouncing a vector written, cleaned up, working, and mostly connected. Now I need to do two things:

--last semester the program was set up to run a certain number of times. I need to go back and look at how I did this.

--when a critter hits a wall, it updates its vector, but then the next timestep, because it's still on the wall, it updates it again, over and over, which means the parasite stays stuck on the wall. It's probably a matter of changing some < to <= or visa versa. I need a reliable way of checking if the vector needs updating or not.

Coding was pretty easy today--I didn't run into many problems at all. God does answer prayer :-)

Wednesday, July 20, 2005

update

This reminds me of one of my friends who said she would not want to marry a computer programmer because when they talk about their day it always goes something like this: it didn't work, it didn't work, it didn't work, it didn't work... and then it did.

I finally started evaluating the expressions piece by piece (which I should have done to start with) and I found the problem. I changed that little piece, and now it works.

programming

ahhh, the joys of programming... or rather banging one's head on the desk because said program refuses to work for no apparent reason. stupid infinite loops....

I talked with Ford today. I'm going to need to figure out how to get my scheme program to output this specific list of number in binary in order for the simrender program to display it:

X size of the World container (float)
Y size of the World container (float)
Z size of the World container (float)
Number of hostcells (int)
Number of parasites (int)
Number of timesteps (int)

radii for each cell (hostcells followed by parasites) (float)

loop for each timestep
loop for each cell
X location of the current cell (float)
Y location of the current cell (float)
Z location of the current cell (float)
go to next cell
go to next timestep

I'm hoping there is some part of scheme that can output binary, and I'm hoping that scheme is smart enough that the floats and ints won't be a problem. And then there's the fun part: getting it to output just a bunch of numbers. Not a list of numbers, not a list of structures, just plain numbers.

we'll see... Meanwhile I'm still trying to get the program to even work. I've got a sweet idea for a very clean loop for when a parasite tries to exit the world, but unfortunately I have to hardwire six different cond statements (plus an else) for it to check individually because it has to do something different for each one and I can't generalize it. So this neat little idea turned into a monster screenfull of code.

Part of me feels guilty for being so stubborn about making Scheme work in this very C++ project, but I like Scheme, and I know Scheme, and even though it probably looks like using Scheme is nothing but jury rigging, that's only because I'm trying to make it work with C++. It's a very nice language.

You know, C++ is linear--it processes one function after another in order till it comes to the end, but Scheme is circular--if everything isn't interconnected, it doesn't work.

Friday, July 15, 2005

progress

I solved the vector problem a day or two ago. As it turns out, I had the W vector pointing down instead of up, which messed up everything. I tried solving it again for a V vector that is angled up instead of down, but for some reason the example I was working on wouldn't work, even though in theory it was fine. So today I started writing some general utility functions for finding the dot product, cross product, magnitude, etc. As well as defining a structure that I'll use for a type of 3D posn. Then I ran into an interesting problem: in Scheme, you can't just give it two equations and tell it to solve for the variable. But I need to do a fair amount of that. I think I have an idea of how to do it, it just isn't as straight forward as it is on paper. *takes deep breath*

I spent most of the afternoon at the wet lab--three of us went over to see the real T. cruzi parasite. It's really cool looking, but it doesn't just swim nicely, it sits there turning somersaults (confused because there aren't host cells near by) or swims slowly and sporadically (contorting itself quickly yet getting almost no where). Does this critter have any kind of attention span unless host cells are near by? And sometimes tons of them cluster together in this huge flower-like ball. So many questions don't have answers yet, it makes things interesting. I'm glad I didn't see the parasite to start with or I might have given up hope of being able to model it. Life isn't neat like computers are. I'll be glad to stick to spheres for a while...

Oh, and guess what I found on Google news today? Three deadly parasites share common genes: scientists. The genomes of three Trypanosomes, including T. cruzi, were published in Science Magazine today.

Tuesday, July 12, 2005

stuckness...



All right. I hope the diagram is readable. I have several problems.
So, we have a vector, V, in the normal coordinate system (which has unit vectors i=(1,0,0) j=(0,1,0) and k-(0,0,1)). We want to bounce it off a wall and end up with vector V'. To make it easier, we define the coordinate system N', N, W with the origin at the point of intersection so that V is now in the plane M' which is shown above. The new coordinate system has unit vectors i'=(2/sqrt(5), 0, 1/sqrt(5)) j'=(0, 1, 0) and k'=(1/sqrt(5), 1, -2/sqrt(5)).

However, and here's the first question: doesn't the vector V have to be converted to the new system (making it V*) before any calculations can be done? I tried doing this two ways: ("*" is unfortunately also dot)

first, from the original packet:
V* = (V * i' , V * j', V * k')

next, as in the book:
V* = ( (i * i')Vx + (j * i')Vy + (k * i')Vz , (i * j')Vx + (j * j')Vy + (k * j')Vz , (i * k')Vx + (j * k')Vy + (k * k')Vz )

I tried the calculations for alpha and beta with both results. Only the first value for V* gave alpha and beta that passed the Pythagorean theorem test. So, second question: Why do I only use the way in the book for converting the V' back to the original coordinate system?

However, and this is kind of a side track, if alpha can be found by dotting -j' with V*, why can't beta be found by dotting -k' with V* ? I tried it, and it doesn't pass the Pythagorean test. Is it because V* is wrong, or is it just illegal somehow?

In any case, using the first way of finding V* and the ways of calculating alpha and beta that were in the last packet, I found V'=(0, 1, -sqrt(5)), and then used the way we worked out before based on the book to find V' in the original system and got V'=(1, 2, 4). The original vector in the original system was V=(1, -1, -2).
The length of V' isn't the same as V, the angle between them is not 2(theta) and V' isn't pointing the correct direction. So I know the answer isn't right, but I haven't been able to find what I'm doing wrong.

Monday, July 11, 2005

vectors going better

Just in case you were worried I'd never update this...

I worked on finding the post-bounce vector today from the packet Tarynn gave me, which basically meant plugging test values into the general equations. It seemed like there were a lot less calculations than there were before--though it usually feels that way once things get properly organized. Not that it didn't take me three hours to work it all out though. There were several parts I just had to sit and stare at for a while until I figured out what was going on. Finally got an answer--V was (1, -1, 2) so V' came out to (1, 2, 4)--however, I've been thinking about it and I don't think it's right. I'm planning on testing/troubleshooting tomorrow.

If I don't catch you before I leave, Tarynn, I'll be back and online hopefully by 7pm your time.

Friday, July 01, 2005

Vectors

Ok, mentally nailed down how to find the intersection of a plane and a line.

I think I mostly understand dot product, but I don't understand how the one angle you get from the dot product relates to the three angles you get (one each for x, y, and z) from direction cosines. AND I still don't understand what it means for the angles of the "post bounce" vector to be reflections of the angles of the "pre bounce" vector. For example, if the angle between the incoming vector and the local z-axis is 30 degrees, then is the angle between the outgoing vector and the local z-axis 60 degrees? 330 degrees? -30 degrees? ...and then what do I do with it?

I don't understand the cross product at all (I don't know anything about matrices).

Here's some demo code for how the location will be updated based on the vector:

(define TIME-UPDATE .5 seconds)
(define TIME-REFRESH .1 seconds)

critter's vector: (vx, vy, vz)
critter's location: (x, y, z)

every TIME-REFRESH the location is updated:
(make-location
(+ x (* TIME-REFRESH (/ vx TIME-UPDATE)))
(+ y (* TIME-REFRESH (/ vy TIME-UPDATE)))
(+ z (* TIME-REFRESH (/ vz TIME-UPDATE))))

then every TIME-UPDATE the vector is recalculated as well.
If the critter bumps into the wall during a refresh, it moves only as far as the wall and immediately updates its vector, then continues moving in the new direction on the next refresh. At the next time-update the vector is re-updated normally.
Both the TIME-UPDATE and TIME-REFRESH can be set as low as the computers can handle.

The thing is, a critter's movement can only be so continuous, because no matter what equation its movement is based on, it can't move only half a pixel. Of course, if this were displayed on a huge monitor (critters that used to be a millimeter in diameter now being displayed as a centimeter in diameter for example), being able to move very small distances would matter a lot more. I guess it is more important to calculate the position accurately and then let your equipment display it however it can.