Another method I've recently made in java is a sine (sin) method which returns the sin value of a number.
public double sin(double angle, String type)
{
double length = 0, x;
if(type == "deg") //Change to radians if not already
{
angle = (angle/180)*(Math.PI);
}
x = angle; // x is easier to work with than a word
while(x > Math.PI) //Bring x into the accurately represented range.
{
x = x-(2*Math.PI);
}
while(x < -Math.PI)
{
x = x+(2*Math.PI);
}
//The polinomial calculation
length = (x-(Math.pow(x, 3)/6)+(Math.pow(x, 5)/120)-(Math.pow(x, 7)/5040)+(Math.pow(x, 9)/(362880))-(Math.pow(x, 11)/39916800));
return length;
}
This is where maths and technology come together beautifully. You see, a computer is a very stupid thing, literally the only piece of maths it can do at it's most basic level is add. Luckily maths at its most basic level is also just adding. So to do other maths functions we need to add in a certain way a certain number of times. For example subtraction is just adding a negative number, multiplication is just adding a number several times. You get the idea. However trigonometry functions(sin, cos, tan etc) are different, they cannot be calculated using addition alone so they pose a serious problem to computers. This is where maths comes to the rescue. In the area of sequences and series there is a special kind of series called a Maclaurin series, I won't bore you with how it's calculated but the great thing about them is that they can be used to model other functions in maths, like sin, with only the use of adding! Here's the formula for them:
f(x) = f(0)+ f '(0)*x + f "(0)* x^2/2!+ f "'(0)*x^3/3!+...+ f(n)(0)*x^n/n!+....
I say "model" because this formula is almost never totally precise but it's pretty good. If you were to work out this formula to infinite terms ie: n = ∞, then you would get an exact answer but we don't have enough time to do that, not even with a very very fast computer. It's alright to stop calculating at about the fifteenth term because the number you calculate would be accurate to about the tenth decimal place which is plenty for most applications. So when you do a trig function on your calculator it's not actually giving you back the trig function, just something very much like it.
When you actually implement a piece of code to calculate sin you have to handle the input number being greater than PI or less than -PI because sin goes for ever to infinity and to negative infinity and the pattern repeats every 2PI. The polynomial which is the Maclaurin series only accurately models sin from about -PI to PI which means if the input number passed into the method is grater than Pi you have to subtract 2PI from it over and over again until the number is within the accurate range. Or if it's less that -PI, you must add 2PI onto it until it's within range. Doing this doesn't change the output number because the value at any one point is equal to the value at that point +/- 2PI. It's a repeating pattern.
This is what y = sin(x) looks like.
This is what the Maclaurin series representation of y = sin(x) looks like.
And this is them laid on top of one another. As you can see, they're basically identical from about - 4 to 4.
Sunday, 29 September 2013
Sunday, 18 August 2013
Factorial method.
One of the things we have been learning about in computer
science at college is using methods in programming. Methods are an absolute god-send. Rather
than having to write big long strings of code, instead you can group a small
chunk together and give it a name, and then retrieve that small piece of code
at any time with just one line.
Here is an example method.
int a_plus_b;
Public void add(int a, int b)
{
a_plus_b
= a + b;
}
"Int a_plus_b" is a global variable, that means it can be used
or changed at anytime, anywhere in the program. The bit between the curly
brackets is the code that the method executes. ‘a’ and ‘b’ are the formal parameters
of the method. "Public" means the method can be called from anywhere in the program. "Void" means the method doesn’t return a value. "add" is simply the name of the method and this
could be anything you like, it could be "pony" or
"omnibus", but it's convention to call methods something to do with
what they do. "Int a_plus_b" isn’t part of the method, but I had to
declare that variable. "Int" just means that the variable type is a number. To implement or "call" this
method you would write the following line:
add(2, 3);
Where 2 and 3 are the
actual parameters you put into the method but these can be any number you
want. So when you write “ add(2, 3); ” the value of “a_plus_b” becomes 5,
similarly if you were to write “ add(18, 5) “, “a_plus_b” would be equal to 23.
This is a method I wrote to return the factorial of a
number.
If you don't know what a factorial is, it is when you multiply a number by each number that comes before it. The symbol for factorial is '!'. So, 3! = 3x2x1 = 6. Similarly 5! = 5x4x3x2x1 = 120.
If you don't know what a factorial is, it is when you multiply a number by each number that comes before it. The symbol for factorial is '!'. So, 3! = 3x2x1 = 6. Similarly 5! = 5x4x3x2x1 = 120.
public int
factorial(int a) //Method
declaration. The input to this method must be
{ // an integer
(a)
int afact = 1; //afact
will be used to generate the factorial and will
//be
equal to the factorial of a.
boolean neg = false; //Declaration
of a Boolean variable to state if ‘a’ is positive
//or negative.
if(a < 0) //If
a is negative (less than zero) neg, which stands for //negative will be set to true.
//else it will stay as false.
{
neg = true;
a*= -1; //If
a is negative, it must be changed to positive.
}
if(a == 0) //The factorial of 0 is one, so
if a is 0, afact must be 1.
{
afact = 1;
}
else //a will only get here if it is
a positive integer.
{
while(a >= 1) //In
the while loop, afact gets multiplied by (a) and then
//(a-1), and then (a-2) and so on down
to 2 and 1.
{
afact=afact*a;
a--;
}
}
if(neg == true) //Finally, if the input number was negative, which
was
//checked for earlier, the output
number gets changed to
//negative.
{
afact*= -1;
}
return afact;
}
And that is how you calculate a factorial, at least it’s one
way, there are more mathematically precise ways of doing it, but this method
works for integers and I’m happy with it. A few weeks after I wrote this
method, my teacher taught the whole class a factorial method which was amusing
for me as I’d already written this one.
Saturday, 17 August 2013
ALBATROSS!!!
It’s been a long time since I’ve posted here, more than six
months in fact. But I’ve been very busy with college work lately so I haven’t
had much time to make things. So rest assured I haven’t forgotten about this
blog, I’m just concentrating on school at the moment. I’m currently studying
maths specialised, physics, advanced electronics and computer science at
college. For you American readers out there, that’s a Tasmanian college, it’s
not like a university. It’s years 11 and 12, just before university. We’ve just
had our mid-year exams and I thought this was a good time to write about my
most recent project.
A few weeks ago my friend had a fancy dress birthday party,
I went as the albatross seller as played by John Cleese in Monty Python. It’s
something I’ve always wanted to do, don’t judge me. The outfit wasn’t difficult
to find, I just went to a costume hire shop but the albatross proved to be much
harder. Weeks before the event, I scoured the internet looking for stuffed toy
albatrosses. Or any sort of albatross at all. I looked through EBay, model
shops, toy shops and Monty Python even had their own albatross-in-a-tray plush
toy. But there was nothing in stock or in my price range anywhere. Buying
albatrosses is harder than you might imagine! So in a moment of desperation, I
decided to make the damn thing myself.
![]() |
| John Cleese (left) and Terry Jones (right) Performing live at the Hollywood bowl. This is pretty much what I looked like on the night. |
Here is a link to that Performance, and a warning, this does contain coarse language.
(Very coarse!) http://www.youtube.com/watch?v=wrqW_BZu5Xk
The first thing I had to do was decide what materials to make
it out of. To start with, all of this was very hard for me; I hadn’t made a model
of an animal since grade 2. That was a Platypus and it was made from chicken
wire and paper mache. After talking to some of my more artistic friends, who do
this sort of thing a lot, chicken wire and paper mache is what I went for. I
made a wire frame in the general shape of an albatross, just based on pictures from
the internet. It has a wingspan slightly narrower than a doorway; I did this
deliberately just to make it practical.
The wire frame then had to be covered with chicken wire, and
for this I used ½ inch hexagonal chicken wire. It wouldn’t be good enough to
simply stretch chicken wire over the frame because it would flatten out in the
sections between the frame wires. So to give it some “form”, I stuffed the body
and part of the wings with tissue paper. That certainly made it more "solid".
I’m not really sure why I did this, it just seemed right at
the time. I
covered the whole thing with masking tape. I think it was to smooth-out the surface a bit before applying the paper
mache. If that is indeed what it was for, it certainly seemed to work.
The tail was very satisfying, it looks really nice but it
was so simple to make. All I did was poke wooden skewers into the rear end in a
sort-of fan pattern and then put masking tape over it. I think the effect works
really well.
The paper mache was pretty easy. It was suggested to me to
use PVA mixed 50/50 with water and really long strips of paper, again by my
artistic friends.
Next was the beak. At last back to familiar territory,
because it’s made from balsa wood. Before I even started to make the frame, I
cut out two pieces of 12mm balsa easily big enough to make the beak and glued
them together side by side. I made two of these in case I messed the first one
up. But the carving and sanding all went fine and it looks just like an
albatross beak.
The next thing was to paint it. This is where I needed help;
I’m not that good when it comes to painting things artistically, which is what
was needed here. So I asked my good friend Kat to paint it for me because she’s
really good with those sorts of things and I’m glad I did because, as I’m sure
you’ll agree, it looks great!
The day of the party: First class has just finished, I rush
to the shops to buy the rest of the things I need to finish the albatross box, and
I then go home in my free to work on it. I still had the box and the straps to
make so it was a bit of a rush job. The box is made of 3mm corflute and the
straps are just one inch wide red ribbon. The box is simply taped together,
nothing fancy, and the straps are stapled on. But it all held together and that
night, I had a lot of fun making everyone at La-Porchetta have a good laugh.
Sunday, 3 February 2013
RC kart
I've set it up to run now, so the brakes work, the steering works and the fuel and exhaust systems are in place and lately I've been having a little bit of fun, err... I mean practice, at driving it. And I can report that there is plenty of power, there's no shortage on the power front, everything is hunky-dory there. In fact there may be a bit too much power, every time I accelerate the wheels spin and because it has such a short wheel base, the back flicks round and it's facing in the opposite direction in an instant. So there's not much more I an tell you about the handling of this kart because it spends most of the time going round in circles. However I have only tested it on gravel so far and wheel spinning is probably entirely expectable, so I will report back to you the moment I get to test it out on a a proper tarmac surface. And frankly I can't wait, because I expect this to be seriously fast!
You can really see the shape starting to emerge now, especially when you compare it to a picture of the real one.
Lately I have been working on the go-karts brakes and bodywork. The brakes that I've used are actually for a model motorbike but they are a good scale match for the kart. As you can see in the picture, I had to make some modifications to the brake caliper to make it fit.
To mount the caliper I simply made a small aluminium bracket which bolts onto the left side bearing. It took a long time to make because it has to be in a very specific position.
The servo which operates the cable operated brakes is mounted on the chassis, exactly where the brake master cylinder is located on the chassis of a real kart.
The front nose cone, ready for painting.
This is what the model and the original one look like together. Hopefully the model will end up looking a little less battered and bruised than the real one.
Monday, 21 January 2013
1/3 scale RC Go-Kart
By all measures this project has surely got to be the
definition of ambition. The project is to build, from scratch, an RC third
scale go-kart on a shoestring budget. I've already spent about three years on
it.
Now I realise that, for “RC people”, 1/3 scale may sound very
big but you have to remember that a real kart is quite small anyway so it’s
about the size of an eighth or tenth scale car, quite manageable.
Why did I decide to build an RC go-kart? Well I love RC, and
I like building things and I used to race ‘real’ karts. So I thought why don’t
I combine the three and build a remote control go-kart?
You might be thinking why didn't you just buy an RC go-kart?
Well there’s no shortage of RC karts on the market, some of them quite cheaply
too, take the Turnigy kart: http://www.hobbyking.com/hobbyking/store/__15284__TURNIGY_1_4_Scale_Brushless_GoKart_ARR_.html
or for a slightly more expensive option, how about the Kyosho BIREL R31-SE? http://www.kyosho.com/eng/products/rc/detail.html?product_id=104501
And of course there are several others. Now these are all very well but
none of them are really true to scale. In terms of their structure, they have
mock frames which are there only for aesthetics, and then they have sub-chassis
which are load bearing. They also have features that are very different to a real
go-kart like the fuel tank in the wrong place, the break disc on the wrong side
and in the Turnigy’s case being electric powered. These are things which, in my
mind, shake their very identity as go-karts. They are also not true to scale in a rather
more literal sense, let me explain. The Turnigy claims to be 1/4 scale but the
Kyosho, which is exactly the same size to within a few millimetres, claims to
be 1/5 scale. But in fact they’re both wrong, and I know because I've checked
this, they are both about 1/4.5. So how could I be expected to buy something
that doesn’t even know what size it is? Another reason I went with the DIY
option is that I had a TRAXXAS T-MAXX and I was getting a little board with it
so I thought I’d take the engine and radio and so-on out of it and make
something else for them. The engine was, in terms of external dimensions, a
perfect 1/3 scale match for the full-size kart I had but there was no one who
sold 1/3 scale karts, not even 1/3 scale kart chassis. Most of the karts on the
market were smaller than 1/3 scale and frankly, I wanted my go-kart to be
bigger than that.
If there is anyone out there selling 1/3 scale karts or someone
who has made one, I would love to hear from you.
![]() |
| This is what it will eventually look like. This is the ‘real’ kart I used to own and race. |
For the frame I used 6mm copper tube which is not ideal as
it should be 11mm to be true to scale but that’s all I could find, compromises
must be made. My thanks to my grandpa who helped me silver solder the chassis. You
may have noticed that the steering arms are bamboo skewers, that’s just because
I don’t have some threaded rod for them yet.
The engine I’m using is a Traxxas TRX2.5 which I ripped out
of my old T-MAXX. I made the rear axle and stub axles at school where I had
access to a lathe. On a real kart the drive is transferred to the axle via
chain and sprockets, which means the engine rotates in the same direction as
the axle. The problem with the TRX2.5 is that is rotates in the opposite
direction to the axle, and it has a gear, not a sprocket. The solution I chose
for this was to have the pinion gear on the motor meshed with the spur gear, from
the T-MAXX, on the axle. This solution eliminates the need for a chain and
sprocket and also reverses the rotation from the engine so the kart actually
goes forwards. Unfortunately this means that the drive system is not true to
scale but I think it was the best compromise. Another thing that’s a compromise
is the rear wheels, well it’s not really a compromise, as there was no other
option for them. They are a few millimetres small in diameter, they’re way too
narrow and they have studs on them as opposed to racing slicks. The go-kart
tire is such a unique shape that there is simply no 1/3 scale substitute.
However the studs will come off with a few donuts so I’m not worried there.
I’ve started working on the body panels now. They will be
made from fibreglass even though the real ones are made of plastic; this is
because I wanted to make something out of fibreglass as I haven’t used it
before, you won’t tell the difference. I’ve made the body panel moulds out of
polystyrene and I’ll cover them with fibreglass, and then dissolve away the
foam. After that they’ll need a little bit of cleaning up and then they’ll be
ready for painting.
The original nose cone and the 1/3 scale nose cone mould.
|
Once I laid out the chassis and the body panels, I suddenly got an idea of just how big this model is actually going to be. The rear track is about 415mm and the front, 325. It’s about 530mm in length which is roughly comparable to a 1/10 scale car or off-road truck.
Friday, 14 December 2012
RC Cap 21
This is a project that I've been working on for about two
years and I've just finished it. It’s a 1/6
scale RC Mudry Cap 21. I got the plans out of a RCM&E magazine August 2007 edition. Credit to Peter
Miller who designed this model, it’s a very nice plane and it was a good set of
plans.
Pete mate, I did make one small change to your plans, I enlisted snoopy as the pilot.
Some of the more observant amongst you may have noticed that the black lining around the canopy is in fact duct tape and that it creases around the curve. Don't worry, that's just because I didn't have any black paint, as soon as I do then I'll do a proper job on it. Also there is no stepping pad on the wing next to the cockpit and this too is because I didn't have the right materials at hand but I'll get round to it sooner or later.
The first job was to cut out all the formers of which there are a lot and each one is different, and they're all pretty tricky.
After a lot of work I finally managed to get one wing done.
After a lot more work I got the other side done along with the ailerons, servo, bellcrank and former strips.
The beginnings of the fuselage.
The fuselage is actually not far from being done here, it's mostly the engine cowl that needs work. Work that I put off for a long time because I really wasn't looking forward to it.
Engine now in with a brand new prop and spinner.
From this point onward I forgot to take any more pictures until all of the white covering was on.
I think it looks good. The cowl is completely finished now and I pushed the boat out with some brand new undercarriage and wheel pants.
This plane is a replica of one specific Cap 21 so the colour scheme and the registration are the same as the real F-GAUK however the real F-GAUK didn't have wheel pants but some other 21's did and I think they look nice.
There are a couple of things on this plane that I am particularly proud of, namely the canopy and the "TOTAL" decals because I made both of them myself. I made the canopy by first making a mold of the shape of the canopy in plaster but in hindsight wood would have been better and then I got a large soft-drink bottle, cut it up and stretched it over the mold while heating it with a head gun. The plastic contracts in heat and forms very nicely around the mold. To make the decals I got the logo off the internet, printed it out to the right size and then painted each side several times with clear enamel paint, this I hope should protect the paper inside. To apply them I simply smeared epoxy on the back and stuck it on, simple as that. It will be interesting to see if my little invention withstands the test of time.
This is a beautiful plane I really enjoyed making it, mostly, but I'm so glad it's finished now. It looks absolutely stunning, the dogs kahooners!
Thursday, 13 December 2012
2012 Robotics.


For
the past four years I have been involved in Robocup junior at a regional, state
and national level. The first year I did Robocup I was in grade 8 and it was
the first time I had ever been involved in robotics. Being a builder type
person, my robot was the best and toughest in my robotics class. Unfortunately
that was my first time programming so whilst our teams robot was good, it had a
rubbish programme on it and we came dead last in the competition. That was
probably a good thing in an odd way because it taught us how competitive these
events are and how good your robots have to be. All of this made me work harder
and the next year when I paired up with my now good friend John, who is amazing
at everything by the way, we came just THIRD in the state titles. The first
year I did Robocup I did soccer but the second year I did rescue. Robot soccer
is pretty self-explanatory but rescue is a bit tricky. Basically the robot must
follow a black line on a white mat and negotiate a series of obstacles on the
way. Once it gets to the end of the course it then has to pick up a soft drink
can and place it on top of a 70mm high block of wood, and of course points are
awarded along the way for completing the sections. It’s harder than it sounds!
Trust me! Last year I paired up with
John again and we did really well, we won the state competition and came fifth
at the nationals. This year we brought two more people onto the team and with
guidance from the other three; I built the robot that you see here. It is a
very far cry from the Lego robots we built in previous years and it was the
best robot at the national competition, I know this because our team won the engineering
award which consists of a $2000 scholarship each to an engineering university.
Unfortunately the award was only open to grade 12’s, they were all in grade 12,
I was in grade 11, which is a bit unfair really considering I BUILT THE WHOLE DAMN
ROBOT! So, they owe me big time. The
rules state that each team must write a logbook of the robots construction and I've put mine on Google doc’s which you can view at the link. As far as the competition went, we didn't go
very well at all, because whilst the robot is very very very good (not my
words) and our programmer had written an amazing programme there were some
tricky technical issues with the sensors which we simply could not overcome.
That was quite disappointing and also quite embarrassing because the robot
looks so good but its performance was pretty poor. In summery I enjoyed the
whole experience, it was great to have a piece of engineering that I created win
an award. That was a very proud moment. I also enjoyed working with the others
on the team; I genuinely believe that all four of us are something special.
Subscribe to:
Posts (Atom)



















