math

moving items in JPanel

I am working on a pong game and I am working on the mechanism to move the ball. If I add 1 to x the ball moves 1 pixel to the right, if i add 1 to y the ball moves 1 pixel to the bottom. What if I want to move the ball at a certain angle how can 1 calculate the coordinates. ...

Difference between Discrete Structures and Discrete Mathematics

I haven't yet found a good answer. Or any answer, for that matter. I've been asked to teach a discrete structures for CS course, but at the same time make sure it's not a discrete mathematics course -- that's offered by the Mathematics department. Many colleges offer a discrete structures course. There are also many DS textbooks. But wh...

Covering Earth with Hexagonal Map Tiles

Many strategy games use hexagonal tiles. One of the main advantages is that the distance between the center of any tile and all its neighboring tiles is the same. I was wondering if anyone has any thoughts on marrying a hexagonal tile system with the traditional geographic system (longitude/latitude). I think it would be interesting t...

How to know when Big O is Logarithmic?

My question arises from the post "Plain English Explanation of Big O". I don't know the exact meaning for logarithmic complexity. I know that I can make a regression between the time and the number of operations and calculate the X-squared value, and determine so the complexity. However, I want to know a method to determine it quickly on...

Polygon math

Given a list of points that form a simple 2d polygon oriented in 3d space and a normal for that polygon, what is a good way to determine which points are specific 'corner' points? For example, which point is at the lower left, or the lower right, or the top most point? The polygon may be oriented in any 3d orientation, so I'm pretty sur...

invalid arithmetic operator

Hello, working with cygwin and writing a script to show my my current ip address minus 2. For some reason it is giving me the follwing error: ")syntax error: invalid arithmetic operator (error token is " this is the script I am using. $ cat test3.sh #!/bin/bash # function IPADDRESS { v=$4 echo $1.$2.$3.$((v-2)) } ADDRESS=$(...

Add distance onto coordinate

I have a unit vector, a distance and a coordinate and I would like to calculate the new coordinate given by adding the distance onto the coordinate in the given direction. How do I do this? ...

Swap the values of two variables without using third variable

How many different ways can you come up with to swap the values of two variables without using any third variable ? I use this one: a^=b^=a^=b ...

log2 not found in my math.h?

I'm using a fairly new install of Visual C++ 2008 Express. I'm trying to compile a program that uses the log2 function, which was found by including using Eclipse on a Mac, but this Windows computer can't find the function (error C3861: 'log2': identifier not found). The way I understood it, include directories are specific to the IDE...

Representing integers in doubles

Can a double (of a given number of bytes, with a reasonable mantissa/exponent balance) always fully precisely hold the range of an unsigned integer of half that number of bytes? E.g. can an eight byte double fully precisely hold the range of numbers of a four byte unsigned int? What this will boil down to is if a two byte float can hol...

Converting a decimal to a mixed-radix (base) number

How do you convert a decimal number to mixed radix notation? I guess that given an input of an array of each of the bases, and the decimal number, it should output an array of the values of each column. ...

How to convert an equation into formulas for individual variables?

How to convert an equation into formulas for individual variables? I am thinking about a math equations like: c^2 = a^2 + b^2 I would like to have a function that could process any formula, and give me the individual variable formulas. The above equation would produce the following: a = (c^2 - b^2)^0.5 b = (c^2 - a^2)^0.5 c = (a^2 +...

Is there a way to find the row of a given cell in an ordered matrix?

For example, given a matrix: 01|02|03|04|05 06|07|08|09|10 11|12|13|14|15 And knowing that the matrix is 5x3, is there a way that if given the value '7', that we can know it is in row 2? The case is that the matrix is always ordered from 1 to n, starting from 0. Lastly, the matrix is stored linearly in a zero based array....

Computing (a*b) mod c quickly for c=2^N +-1

In 32 bit integer math, basic math operations of add and multiply are computed implicitly mod 2^32, meaning your results will be the lowest order bits of the add or multiply. If you want to compute the result with a different modulus, you certainly could use any number of BigInt classes in different languages. And for values a,b,c < 2^3...

cocos2d help find points on a circle

I am trying to solve a tricky math problem, in a cocos2d for iphone context. Basically I have a roullette wheel which is rotating over time. I want to have a Sprite latch onto the wheel at certain points (like compass ordinal points N, S, E, W) and bounce off at all other points. I have the image of the wheel rotating, and just need t...

boolean algebra article/book

i got really confused every time when i encounterd bit operations,especially those shifts,rotates,overflow things etc.I wonder if there's any book/article on the web introducing boolean algebra,which could give me a solid background of boolean algebra,thanks! ...

How to make this Matrix class easier to use in the debugger

I've written a C++ matrix template class. It's parameterized by its dimensions and by its datatype: template<int NRows, int NCols, typename T> struct Mat { typedef Mat<NRows, NCols, T> MyType; typedef T value_type; typedef const T *const_iterator; typedef T *iterator; enum { NumRows = NRows }; enum { NumCols = ...

Maple and substrings

Maybe this is the wrong website to ask, but hopefully somebody knows... How do I break a string in Maple and store it in a list of substrings? i.e. my string is : "i love the weekends" and I want to break it into substrings of size 2... so i would look like this substrs; substrs = [[i ][lo][ve][ t][he][ w][ee][ke][nd][s ]] ...

Symbolic Mathematics for .NET

I am looking for symbolic mathematics library for .NET framework. I have looked at Math.net but it's not something usable yet. Do you know if there is another library exists? ...

c#: Rotating Text within a custom control

I am attempting to rotate some text within a label. I have a cusom label which allows me to have control over the text rendering process. protected override void OnPaint ( PaintEventArgs pe ) { Graphics g = pe.Graphics; g.RotateTransform( angle ); g.drawString( text ); g.ResetTransform(); } The problem I am having i...