math

Scaling ratio of two different resolutions

I have two different resolutions, the original one is 567x756 (wXh), the one which I want to display is 768x1024 (wXh). How to find out the scaling ratio for these two resolutions? For example if the font size used in 567x756 resolution is 7 pts then whats the values I should multiply with the font size (7 pts) to display the text in 768...

Determining if and where a photon will collide with a polygon in 3D space.

The problem is straight forward: 1) We have a photon traveling from Point 1 (x,y,z) to Point 2 (x,y,z), both of which could be located anywhere in 3D space. 2) We have a polygon that is both rotated randomly on the x-axis and/or y-axis and also located anywhere in 3D space. 3) We want to find: a) if the photon will collide with the p...

ActionScript Negating a Number

i'd like to negate a number and would like to know if there's a built in method that will convert a negative number to a positive OR a positive into a negative, depending on the number. i know about Math.abs(), but that only seems to convert negative into positive. is there a method that will do both? ...

Does acos, atan functions in stl uses lots of cpu cycles

Hi all, I wanted to calculate the angle between two vectors but I have seen these inverse trig operations such as acos and atan uses lots of cpu cycles. Is there a way where I can get this calculation done without using these functions? Also, does these really hit you when you in your optimization? ...

Determine if point intersects 35km radius around another point? Possible in Linq?

Assume I have a point at the following location: Latitude: 47°36′N Longitude: 122°19′W Around the above point, I draw a 35Km radius. I have another point now or several and I want to see if they fall within the 35Km radius? How can I do this? Is it possible with Linq given the coordinates (lat, long) of both points? ...

Creating combinations that have no more one intersecting element

I am looking to create a special type of combination in which no two sets have more than one intersecting element. Let me explain with an example: Let us say we have 9 letter set that contains A, B, C, D, E, F, G, H, and I If you create the standard non-repeating combinations of three letters you will have 9C3 sets. These will contain ...

adding up value of array and getting the average

I have an array that looks similar to this, [4] => Common_Model Object ( [id] => 4 [name] => [date_created] => [last_updated] => [user_id_updated] => [_table] => [_aliases] => Array ( [id] => 4 [name] => [date_c...

Python division

Can somebody explain this to me? I was trying to normalize a set of numbers from -100 to 0 to a range of 10-100 and was having problems only to notice that even with no variables at all, this does not evaluate the way I would expect it to: >>> (20-10) / (100-10) 0 EDIT: float division doesn't work either: >>> float((20-10) / (100-10...

Code Golf: All +-*/ Combinations for 3 integers

Write a program that takes 3 integers separated by spaces and perform every single combination of addition, subtraction, multiplication and division operations possible and display the result with the operation combination used. Example: $./solution 1 2 3 Results in the following output 1+2+3 = 6 1-2-3 = -4 1*2*3 = 6 1/2/3 = 0 (in...

Solve Physics exercise by brute force approach..

Being unable to reproduce a given result. (either because it's wrong or because I was doing something wrong) I was asking myself if it would be easy to just write a small program which takes all the constants and given number and permutes it with a possible operators (* / - + exp(..)) etc) until the result is found. Permutations of n di...

Can I use a switch to hold a function?

I have a 3 file program, basically teaching myself c++. I have an issue. I made a switch to use the math function. I need and put it in a variable, but for some reason I get a zero as a result. Also another issue, when I select 4 (divide) it crashes... Is there a reason? Main file: #include <iostream> #include "math.h" #include <stri...

How do I determine a best-fit distribution in java?

I have a bunch of sets of data (between 50 to 500 points, each of which can take a positive integral value) and need to determine which distribution best describes them. I have done this manually for several of them, but need to automate this going forward. Some of the sets are completely modal (every datum has the value of 15), some a...

0/1 Knapsack with irrational weights

Consider the 0/1 knapsack problem. The standard Dynamic Programming algorithm applies only when the capacity as well as the weights to fill the knapsack with are integers/ rational numbers. What do you do when the capacity/weights are irrational? The issue is that we can't memoize like we do for integer weights because we may need pote...

Optimal rotation of 3D model for 2D projection

I'm looking for a way to determine the optimal X/Y/Z rotation of a set of vertices for rendering (using the X/Y coordinates, ignoring Z) on a 2D canvas. I've had a couple of ideas, one being pure brute-force involving performing a 3-dimensional loop ranging from 0..359 (either in steps of 1 or more, depending on results/speed requiremen...

PHP: need more decimal places for sinus calculation

Hi volks, to calculate some longitude and latitude values I need more decimal places like mysql is possible to do. For instance with mysql I get this result: cos( RADIANS( 47.685618 ) ) = 0.67319814951254 With PHP 5.2 I only get: cos( deg2rad( 47.685618 ) ) = 0.673198149513 Two decimal places shorter but I need them. I know I a...

What would be a good general algorithm for approaching integer sequence problems?

Say the input will always be the same number N of numbers (e.g., 5) and assume the integers actually have a mathematical relation (no lengths of the numbers 'one', 'two', days in the nth month, etc.). The output would be either the next integer and the rule discovered or a message that no rule could be detected. I was thinking to have in...

Finding the highest, lowest, total, average and median from an array in Ruby

I am creating a boxplot generator in Ruby, and I need to calculate some things. Let's say I have this array: arr = [1, 5, 7, 2, 53, 65, 24] How can I find the lowest value (1), highest value (65), total (157), average (22.43) and median (7) from the above array? Thanks ...

Is there a 128 or 256 bit double class in .net?

I have an application that I want to be able to use large numbers and very precise numbers. For this, I needed a precision interpretation and IntX only works for integers. Is there a class in .net framework or even third party(preferably free) that would do this? Is there another way to do this? ...

How to parse mathematical expressions involving parentheses

This isn't a school assignment or anything, but I realize it's a mostly academic question. But, what I've been struggling to do is parse 'math' text and come up with an answer. For Example - I can figure out how to parse '5 + 5' or '3 * 5' - but I fail when I try to correctly chain operations together. (5 + 5) * 3 It's mostly just bu...

Math behind Bump(ing)?

I was randomly looking at the FAQ for bu.mp (http://bu.mp/faq), and this part caught my eye: Q: No way. What if somebody else bumps at the same time? Way. We use various techniques to limit the pool of potential matches, including location information and characteristics of the bump event. If you are bumping in a parti...