math

How to determine ordering of 3D vertices

If I have 5 Vertices in 3D coordinate space how can I determined the ordering of those Vertices. i.e clockwise or anticlockwise. If I elaborate more on this, I have a 3D model which consists of set of polygons. Each polygon is collection of vertices and I want to calculate the norm of the polygon surface. To calculate the norm I have t...

How to calculate quantization error from 16bit to 8bit?

Hi everyone, Does anyone know how to calculate the error of quantizing from 16bit to 8bit? I have looked at the Wikipedia article about Quantization, but it doesn't explain this. Can anyone explain how it is done? Lots of love, Louise Update: My function looks like this. unsigned char quantize(double d, double max) { return (unsi...

Computing GoogleShare of N Terms

I need guidance in how I should compute the GoogleShare of several terms. For example, take the following base terms: "Tom Cruise" = 12,000,000 pages "John Travolta" = 4,900,000 pages Now if we add a second term: "Tom Cruise" + "Scientology" = 784,000 pages "John Travolta" + "Scientology" = 331,000 pages So the GoogleShare for T...

How do I show all combinations?

I searched, can't find anything: How do I do this? I enter $x = 'tlagre'; I want it to return every single letter combination, down to four. i.e. - "tlagr" "gratl" "lat" "rat" I've found some that can do this but none will do every number of letters (they all just do the exact same # of letters as given in $x ...

Calculating scores from incomplete league tables

When I was in high school and learning about matrices, we were shown a technique that would help in a situation like this: There are a number of chess players in a league, and they need to determine a ranking for all of them, but don't have enough time for every player to play every other person. If it ends up that Player A beats Player...

Calculus in Ruby

Basically the title says it all What I mean is differentiation and integration stuff that a CAS would do? (like a Typical handheld CAS if not better) Is it possible? What Gem need to be installed? Anyone had any experience? ...

How to use circshift in Matlab? What am I doing wrong?

Dear developers, I would like to plot the "greasy" test signal in Matlab, and then plot a Gauss function in the same plot. The script below does that. But I would like to be able to place the Gauss function at a certain position, so I see that others often use CIRCSHIFT to move plots. When I use it I can move the Gauss function to the...

How to fix this problem in PHP?

$onethird = 1.0/3; $fivethirds = 1.0/3+1.0/3+1.0/3+1.0/3+1.0/3; $half = 1.0/2; $threehalf = 1.0/2+1.0/2+1.0/2; var_dump($onethird + $fivethirds == $half + $threehalf); which outputs false,but as we all know:5/3+1/3=2=3/2+1/2 How to fix this problem? ...

Java: Performance SQRT Calculations

Hi, I have this code: package math; import java.io.IOException; import java.util.Scanner; public class Main { public static void main(String[] args) throws IOException { System.out.println("Hi, I will beat Java's Math.sqrt(double) method"); System.out.println("Both ways of calculation will be done"); S...

Is (1 + sqrt(2))^2 = 3 + 2*sqrt(2) satisfied in Floating Point arithmetics?

In mathematics the identity (1 + sqrt(2))^2 = 3 + 2*sqrt(2) holds true. But in floating point (IEEE 754, using single precision i.e. 32 bits) calculations it's not the case, as sqrt(2) doesn't have an exact representation in binary. So does using a approximated value of sqrt(2) provide different results for left and right hand sides? I...

Calculating EXIF exposure time as a fraction (Delphi)

Hi, I am trying to display EXIF exposure time as a fraction of seconds but I am not getting expected result, probably a small mistake. I have found two routines that do the calculation but both bring diffrent and wrong result. The value I am having problem is: "0.0806451612903226" value is of type Extended. DecimalToFractStr give m...

Conversion euler to matrix and matrix to euler

I'm trying to convert a 3D rotation described in term of euler angles into a matrix and then back, using .NET/C#. My conventions are: left handed system (x right, y top, z forward) order of rotations: heading around y, pitch around x, bank around z rotations are positive using the left hand rule (thumb pointing to +infinity) My tria...

radians translating radians to degrees

I notice that translating radians to degrees and vice versa is like translating a percentage to a whole number and vice versa. for example , to get 60 percent of 345 you do the following 60 * 345/100 to get 60 degrees in radians you do 60 * 3.14/180 There is a pattern there BUT. we use 100 to compare percentages to a numbe. so why ...

Determining the number of possible combinations

I'm trying to figure out how many possible ways there are to combine various elements form this string. "{Hello|Hi|Hey} {world|earth}{!|.|?}" Where one item (separated by a pipe/|) is selected at random from each group ({}) and combined into a single string. So the above "template" could produce: Hello world. Hi earth? Hey world. Hi...

Cosine Similarity

Hi All, Thank you all great guys here for helping people like me :) I just need small hint .... I calculated tf/idf values of two documents. Following is the tf/idf values 1.txt 0.0 0.5 2.txt 0.0 0.5 The documents are like 1.txt = > dog cat 2.txt = > cat elephant As now I have tf/idf values. Can any body tell me how to use these valu...

Combining euler angles of different coordinate system.

I have two euler angles. e1 = Angle in parent coordinate system (means angle applied to child coordinate system). e2 = Angle in child coordinate system. The two coordinate system may not have same origin, means that child coordinate system could be translated in 3d space. Now how could i combine these two angles so that resulting angle...

Class or Metaclass Design for Astrodynamics Engine

Gurus out there: The differential equations for modeling spacecraft motion can be described in terms of a collection of acceleration terms: d2r/dt2 = a0 + a1 + a2 + ... + an Normally a0 is the point mass acceleration due to a body (a0 = -mu * r/r^3); the "higher order" terms can be due to other planets, solar radiation pressure, thr...

Changing the direction of a ball on collision base on speed

I am creating a ping pong game. And I want to create the ability to control the direction of the ball based on the impact on the paddle. If the ball is coming down at vy = 4; vx = 4; and the paddle is moving to the left at vx = -5; I want the ball to slightly change its course depending on how fast the paddle is moving. It would probabl...

MS Calculator on windows 7. I need to know how it does its operations.

MS calculator on windows 7 has a "programmers" mode. When I type in (in binary): 1111111111111111111111111111111111111111111111111111111111111111 and then click "Dec", the binary turns into -1. When I click Oct, the value turns into 1777777777777777777777 However, whenever I use an online converter, it doesn't work. I need to know ho...

Find the number of divisors of a number given an array of prime factors using LINQ

Given an array of prime factors of a natural number, how can I find the total number of divisors using LINQ upon the original array? I've already figured out most of this problem, but I'm having trouble with my LINQ statement. Math Background: The prime factors of a number are the prime integers that divide evenly into the number wi...