math

Convert axes coordinates to pixel coordinates

I'm looking for an efficient way to convert axes coordinates to pixel coordinates for multiple screen resolutions. For example if had a data set of values for temperature over time, something like: int temps[] = {-8, -5, -4, 0, 1, 0, 3}; int times[] = {0, 12, 16, 30, 42, 50, 57}; What's the most efficient way to transform the dataset...

giving percentages to (overall negative) revenue growth performance

Hey, I have a sampling problem, for an analysis i have to calculate a revenue growth share. I found an article about sampling with negative numbers very helpfull since i have to work with a sum of revenues that is negative. The article suggests to make all the numbers absolute, but unfortunately this does not solve my problem. Since i am...

Convert Fraction to Percent

In our Learning Management System someone in their infinite wisdom decided to keep non-standardized grades. As a result we have a table similar to this: Assignment 1 - 100 Assignment 2 - 80 Assignment 3 - 10/20 Assignment 4 - 68 Assignment 5 - 8/10 As you can see we have a mixture of percentages and fractions. What i'd like to do is ch...

Why are the parameters to `atan2` “backwards”?

Why is it that the parameters to the atan2 function are “backwards”? Ie, why does it accepts coordinates in the form y, x instead of the standard x, y? ...

Formal definitions of Classes and Structs

I remember touching on this subject during a class on programming languages. I vaguely remember that a struct could be seen as a mathematical tuple. Is it possible to describe a class or an object in a similar fashion? ...

A better Ruby implementation of round decimal to nearest 0.5

This seems horrible inefficient. Can someone give me a better Ruby way. def round_value x = (self.value*10).round/10.0 # rounds to two decimal places r = x.modulo(x.floor) # finds remainder f = x.floor self.value = case when r.between?(0, 0.25) f when r.between?(0.26, 0.75) f+0.5 when r.between?(0.76, 0.99) f+...

Finding the points of a triangle after rotation

I'm working on a (rather) simple 2D project in OpenGL. It's some sort of asteroids clone. The ship is basically an isosceles triangle of height H, with the base have a length of H/2. The way I've been doing it so far is simply storing the center point (CP) of the triangle and then calculating the final vertex positions on the fly. The ...

Does gray code exists for other bases than two?

Just a matter of curiosity, is the Gray code defined for bases other than base two? I tried to count in base 3, writing consecutive values paying attention to change only one trit at a time. I've been able to enumerate all the values up to 26 (3**3-1) and it seems to work. 000 122 200 001 ...

How can I check if a point is below a line or not ?

How can I check if a point is below a line or not ? I've the following data: Line [ {x1,y1}, {x2,y2} ] Points {xA,yA}, {xB,yB} ... I need to write a small algorithm in python to detect points on one side and the other side of the line. thanks ...

How can I check if 2 segments intersect ?

How can I check if 2 segments intersect ? I've the following data: Segment1 [ {x1,y1}, {x2,y2} ] Segment2 [ {x1,y1}, {x2,y2} ] I need to write a small algorithm in python to detect if the 2 lines are intersecting. thanks Update: ...

Curve text on existing circle

For an application I am building I have drawn 2 circles. One a bit bigger than the other. I want to curve text between those lines, for a circular menu I am building. I read most stuff about curving a text that you have to split up your text in characters and draw each character on it's own with the right angle in mind (by rotating the ...

Understanding the Math Behind PageRank and Similar Algorithms

I've looked at a bunch of resources provided by similar questions asked on this site, the most helpful so far has been found in this discussion, and the resources linked here: PageRank Explained.. While this provides a detailed overview, I'm looking for something a bit more specific. While I realize there are other factors in play, and...

Computational cost of trig functions

Possible Duplicate: How do Trigonometric functions work? What actually goes into the computation of trig functions like Sin, Cos, Tan and Atan? I think I've found an optimization in my code where I can avoid using any of these functions and base the problem around slope instead of angles. So that means a couple division oper...

Efficiently detect sign-changes in python

I want to do exactly what this guy did: Python - count sign changes However I need to optimize it to run super fast. In brief I want to take a time series and tell every time it crosses crosses zero (changes sign). I want to record the time in between zero crossings. Since this is real data (32 bit float) I doubt I'll every have a numb...

vim replace only for whole-word match

code sameple: for file in files: do_something(root+file) "file" is warned as "redefined symbol", so now I want to replace file to f but I must keep files usually I use below command: :%s/file/f/gcI but it will match files, is there any way to match only whole word, and notice the (root+file) syntax. ...

remove remainder from string in php

Hi. Simple question. I have this code: total = 41 win = 48 echo ($total/$win) * 100 ; printing out 85.416666666667 I need to remove the remainder so it prints out: 85 %. ...

jQuery Math for Color Animation - certain Color Range

I am using this Math for a bg color animation on hover: var col = 'rgb(' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ')'; It produces a random rgb color. Very nice indeed but I look for something different. Does anybody know a good Math that I can use to ha...

n coins. Which is fake?

Possible Duplicate: Algorithm to find minimum number of weighings required to find defective ball from a set of n balls We have n coins. One of them is fake, which is heavier or lighter (we don't know). We have scales with 2 plates. How can we get the fake coin in p moves? Can you give me a hand for writing such a program? No...

How to calculate n log n = c

I have a homework problem for my algorithms class asking me to calculate the maximum size of a problem that can be solved in a given number of operations using an O(n log n) algorithm (ie: n log n = c). I was able to get an answer by approximating, but is there a clean way to get an exact answer? ...

Bounding this program to determine the sum of reciprocal integers not containing zero

Let A denote the set of positive integers whose decimal representation does not contain the digit 0. The sum of the reciprocals of the elements in A is known to be 23.10345. Ex. 1,2,3,4,5,6,7,8,9,11-19,21-29,31-39,41-49,51-59,61-69,71-79,81-89,91-99,111-119, ... Then take the reciprocal of each number, and sum the total. How can this ...