math

How do I think about math in programming?

I'm not sure if this is for SO or not. I am reading some of my old math textbooks and trying to understand math in general. Not how to figure something. I can do that but rather what is it that math is doing. I'm sure this is painfully obvious but I never thought about it until I thought more about game programming. Is it right to t...

Transform a triangle to another triangle

Hi i am trying to create the affine transform that will allow me to transform a triangle into another one. What i have are the coordinates for the 2 triangles. Can you help me? Following the answer by Adam Rosenfield i came up with this code in case anyone is bored to solve the equation himself : public static AffineTransform createTra...

Is there a simple "point in rect" algorithm for a wraparound map?

I'm trying to build a rectangular grid that can wrap around at the edges. Anyone who plays video games will probably be familiar with the concept: go far enough in one direction on the world map and you'll end up back where you started. This causes some difficulty in setting up the viewport, though, since the edges can scroll into nega...

Base 62 conversion in Python

How would you convert an integer to base 62 (like hexadecimal, but with these digits: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'). I have been trying to find a good Python library for it, but they all seems to be occupied with converting strings. The Python base64 module only accepts strings and turns a single digi...

Calculating 'up vector' from transformation matrix in 3D

Hello! I just came to strange problem with my project in 3D. Everyone knows algorythm of calculating LookAt vector, but it is not so easly to calculate "up" vector from transformation matrix (or at least maybe I simple missed something). The problem is following: "Up" vector is (0, 1, 0) for identity rotation matrix and rotate with ma...

Generate my own algebra worksheets to print and use.

I would like to use Python to generate my own algebra to pre-calculus worksheets to print and use. The purpose is to teach kids how to practice algebra. What is the best way generate the expressions? Update: I am planning to use Latex to generate nicely formatted equations. The question I have is how to come up with a large number...

Combinatorics : Grouping Characters Challenges

I was working on some grouping problems at my work. There are quite a few questions, please bear with me. I find them quite interesting. If anyone here is also interested in combinatorics, please help me out. Ok so we have a bunch of characters , here i have taken a i d s. What are the ways we can group the elements ? Let us say we ha...

Platform independent math library

Is there a publically available library that will produce the exact same results for sin, cos, floor, ceil, exp and log on 32 bit and 64 bit linux, solaris and possibly other platforms? I am considering the following alternatives: a) cephes compiled with gcc -mfpmath=sse and the same optimization levels on each platform ... but its n...

Is finding the equivalence of two functions undecidable?

Is it impossible to know if two functions are equivalent? For example, a compiler writer wants to determine if two functions that the developer has written perform the same operation, what methods can he use to figure that one out? Or can what can we do to find out that two TMs are identical? Is there a way to normalize the machines? E...

MySQL Range and Average

I'm wondering if in MySQL you are able to find a range within values along with the average in a query. Assume the table below please: ----------------------------------------- | ID | VALUE | ----------------------------------------- | 1 | 30 | -----------------------------------...

Efficiently determining the probability of a user clicking a hyperlink

So I have a bunch of hyperlinks on a web page. From past observation I know the probabilities that a user will click on each of these hyperlinks. I can therefore calculate the mean and standard deviation of these probabilities. I now add a new hyperlink to this page. After a short amount of testing I find that of the 20 users that se...

What are a few time-consuming operations in C?

I'm looking to write a quick benchmark program that can be compiled and run on various machines. Rather than using commercially/open-sourceally available options, I'd rather have my own to play around with threading and algorithm optimization techniques. I have a couple that I use already, which include recursively calculating the nth n...

what is the most efficient way to pick a random card from a deck when some cards are unusable?

I have an array which tells whether a card is in use: int used[52]; This is a terrible way to pick a random card if I have many used cards: do { card = rand() % 52; } while (used[card]); since if I have only 3-4 unused cards, it'll take forever to find them. I came up with this: int card; int k = 0; int numUsed = 0; for (k=...

How to handle type redundancy in external libraries?

I'm writing a computer graphics application that makes use of several different libraries that provide many of the required features. For example, in college I wrote quaternion, optimized 3 vector, and optimized 4x4 matrix classes that I like to use since they are efficient and I'm very familiar with them. I also wrote a K-D Tree imple...

Large numbers rounding off [c#]

I am having some weird issue here. I have a database table which has huge value stored on a column. My application (C#) is reading this value and keeping in a double type. This application will insert the same value to another table. Note : I am not doing any calculations/processing on the value read from the first table. It is just kept...

How can I find the direction of a Vector2 with only the X and Y coordinates?

Hi, I would like to know 2 things about the struct Vector2 in XNA: Why does this struct only have X and Y instead of X,Y (origin) and X',Y' (destination)? How can I calculate the direction of a vector with only the X,Y? Thanks a lot in advance. Kind Regards. Josema. ...

A Ranking algorithm

I need to sort some products base on user ratings. Suppose we have 3 products {a,b,c} and we have user's feed backs about this products. It's not important which user give us feed back (this question is not about correlative filtering if you are familiar with it - user interests is not the case here) Each of these below lines are feed...

Products Ranking

I need to sort some products base on user ratings. Suppose we have 3 products {a,b,c} and we have user's feed backs about this products. It's not important which user give us feed back (this question is not about correlative filtering if you are familiar with it - user interests is not the case here) Each of these below lines are feed ...

What algorithm can I use to find the shortest path between specified node types in a graph?

This is the problem: I have n points (p1, p2, p3, .. pn), each of them can connect to any other with a determined cost x. Each point belongs to one of a set of point-types (for example "A" "B" "C" "D"...). The input of the method is the path I want to follow, for example "A-B-C-A-D-B". The output is the shortest path connecting the p...

Is there a Java API or built-in function for solving annuity problems?

I was asked by my boss to create a module for calculating reverse compound. The question is: if I want to achieve $1.000.000,00 in 24 months with interest rate 18%/year (or 1.5%/month). how much money do I have to save every month? I searched on the internet, but found nothing except people referring to the Excel formula. Do you know ...