Ok, so there's this coding language called FCML- a simple language built for a scripting engine in a game (Fantastic Contraption). I'm wanting to write a script that implements the graph of an equation in the form of axn+b to that gaming language. To clarify, this is to create a "level", or a series of bricks, and fitting them along the line of a user-specified equation. The coding language is very simple:
StaticRect (x1, y1), (x2, y2), z
Where x1 and y1 are coordinates on a Cartesian coordinate plane, x2 and y2 are lengths and widths of the rectangle, respectively, and z is the rotation of the brick. The brick is positioned with respect to it's center; i.e. it's center is positioned with x1 and y1. It's mathematically possible; it's just very confusing for a 7th grader. With a little calculus, trigonometry, and algebra I've come up with these formulas, and would just like to see what others come up with before implementing them.
Input: y=axn
90-tan-1(1/naxn-1) for z
10 for y2
root((axn-a(x-.5)n) + .25) for x2
axn+.5(axn-a(x-.5)n) for y1
x - .25 for x1
I'm aiming for an accuracy of 1/2.

Tags:

## Discussions

I get the groundwork of what you are trying to achieve, but I'm not sure how you want the bricks to be positioned. Do you want to make a smooth shape like the graph out of rotated bricks, or just position the bricks along the path as steps? The rotation part is harder, as it involves calculus, but fortunately some simple enough calculus that I can remember how to do :) Could you explain how you derived the last three equations? This sounds like quite an interesting problem. I think with a little messing around I could work out an "accurate" solution (ie fit top edges of bricks to a polygonal approximation of the graph). Where did I put my whiteboard...

I'm aiming to make a smooth or semi-smooth graph, mostly by rotation.
I derived the (now revised) first formula (for z, rotation) by taking the derivitive of the function f(x), which the user defines, take the function of f(x-.5), and subtract the two. That gives me the rise, and the run would be .5. Using that scheme, you can create a triangle of sort. Using the inverse tangent, you can convert (.5 / f(x) - f(x -.5) to degrees; just tan-1(.5 / f(x) - f(x -.5).
For the height of each brick (y2), I just set it as a preliminary number to satisfy itself; this is just aesthetic, and won't play a major factor. For x2, the length of each brick, I used a whipped up a quick formula for calculating the distance it's origin and the start point of the next brick. First, it calculates it's start point: f(x). Then, we calculate the start of the next point: f(x + .5). Using the Pythagorean theorem, we can determine the length is equal to √(f(x + .5) - f(x))2 + .25.
The coordinates are a bit more deceptive, since it's considered the middle of the brick. For x, the most obvious thing to put would be x. But considering the run is .5, we have to add half of that to x to make it where we want it. For the locational x coordinate, I concluded that it should be x + .25. For y, it is much more complicated. The base would be F(x), but we have to add half the length. We can't use the formula stated above because it's diagonal length; we want purely vertical length. So, we take it before we apply the Pythagorean theorem. Thus concluded; the formula is f(x) + 1/2(f(x + .5) - f(x)).
Currently on the road, I have no way of implementing them yet, so I have no way of testing them besides with pen and paper. Which is why I decided posting them here for some peers to revise might be a "resourceful" thing to do.