I want to write a pong in C# and XNA with friction and bounce. I tried to implement the collision as described by Garet Rees in a previous question.
Here is the basic algorithm I use for pong:
Seperate the colliding objects so that they are no longer colliding.
Get the surface normal for collision response.
Compute the new velocity - ...
Is it important for developers to know discrete math? Most of the books about algorithms and analysis have at least some references to math. I can easily understand the algorithms in principle and can implement them without any problem, but when it comes to the math parts I get stuck. Is it generally assumed that developers will have dee...
So, I'm trying to figure out the total amount of return from an investment of £5 with a daily interest rate of 1.01%. Obviously, I am wanting the compound interest rate, so I have this so far:
int main() {
double i = 500;
int loop;
int loopa;
double lowInterest;
double highInterest;
lowInterest = 1.01;
high...
Hello,
I'm currently applying to graduate schools, with the intention of getting a PhD in a field between math and CS. I am currently majoring in math, but two years ago I took a class in Haskell and got really interested in functional programming in general. I was interested in both the elegance of the ideas, both the abstract ones and...
I wrote this simple code in python to calculate a given number of primes.
The question I want to ask is whether or not it's possible for me to write a script that calculates how long it will take, in terms of processor cycles, to execute this? If yes then how?
primes = [2]
pstep = 3
count = 1
def ifprime (a):
""" Checking if the pass...
Hi.
I have following equation:
f(N): N = ((1+lam)^3 )/ ((1-lam)*(1+lam^2));
I need to create a function that finds lam for specified N.
Right now I'm doing it using simple loop:
lam = 0.9999;
n = f(lam);
pow = 0;
delta = 0.1;
while(abs(N - n)) > 0.1 & pow < 10000)
lam = lam - 0.001;
n = f(lam)
pow = pow+1;
end
How c...
I am rotating an image around it center point but need to track a location on the image as it rotates.
Given:
Origin at 0,0
Image width and height of 100, 100
Rotation point at C(50,50)
Angle of "a" (say 90 degrees in this example)
Point P starts at (25,25) and after the rotation it is at Pnew(75,25)
I haven't touched trig in 20 y...
Background: I have a bird view's JavaScript game where the player controls a space ship by touching a circle -- e.g. touch to the left of the circle center, and the ship will move left, touch the top right and it will move to the top right and so on... the further away from the circle center of pseudo joystick, the more speed in that dir...
The title says it all actually.
In a simple way, i have an array of 10 values for example..and i would like to multiply each value with 5. Can i actually just do the following?
for (i = 0 ; i <10 ; i++)
{
x[i]=x[i]*5;
}
And what about getting square for values in the array and be stored back into the same array? As in I want x[...
Let's say I have an increasing sequence of integers: seq = [1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 4 ... ] not guaranteed to have exactly the same number of each integer but guaranteed to be increasing by 1.
Is there a function F that can operate on this sequence whereby F(seq, x) would give me all 1's when an integer in the sequence equals x an...
Hi,
I'm looking for something that can interpret a string in php and perform simple math calculation, and then return a boolean result as to whether the expression is true or false.
For example:
Sue types in "3*{mysalary}/9=10000"
PHP splits this up into two expressions - explode('=',string);
PHP takes my list of database fields, and...
Background: I have 8 images for every sprite in my bird's view JavaScript game, representing top, top-right, right, right-bottom etc., depending on the player's space ship speed.
Question: Given the values sprite.speed.x and sprite.speed.y (which could be something like 4 and -2.5, or 2 and 0 for instance), how do I get the correct angl...
I'm wondering if there is a more elegant way of adding a percentage. For example, if I wanted to add 12% of $a's value to $a I'm doing:
$a = 100;
$a = $a + (($a / 100) * 12);
Which gives me 112 as the new value, of course. But I can't help but feel this is a little too verbose and there must be a better way of doing the percentage add...
I am using the Apache Commons math.Fraction class to convert my doubles to fractions, which is working fine.
However, I need it to calculate these fractions in a way that makes sense for displaying lengths in inches, to the nearest 1/32".
For example, converting 0.325 to a fraction yields 12/37, which doesn't make sense to someone look...
Hello,
I looking for a really great math books that explain the following topics and how they can be implemented on PC:
Derivations
Differential equations
Integrals
Matrix operations
I'm OK to read more than one book :) but I want to read really helpful ones.
Thanks!
...
Sorry if this doesn't make sense... I know the length of the triangle segments and the xy coordinates of two points. How do I figure out the xy of the 3rd point?
...
What kind of problems on graphs is faster (in terms of big-O) to solve using incidence matrix data structures instead of more widespread adjacency matrices?
...
Hi, We've got some nonnegative numbers. We want to find the pair with maximum gcd. actually this maximum is more important than the pair!
For example if we have:
2 4 5 15
gcd(2,4)=2
gcd(2,5)=1
gcd(2,15)=1
gcd(4,5)=1
gcd(4,15)=1
gcd(5,15)=5
the answer is 5.
...
I can create a chart with a logarithmic scale on one axis, but I need to have a probability scale on the other axis as well.
Thanks in advance.
...
I have been working on extracting the peak values from a graph (see previous question) which looks like this:
but I have noticed that for some of the xcorr graphs I have been working on the values do not turn out as expected and they normally turn out looking more like this:
and this:
Instead of trying to pick the peak values li...