math

Parsing dice expressions (e.g. 3d6+5) in C#: where to start?

So I want to be able to parse, and evaluate, "dice expressions" in C#. A dice expression is defined like so: <expr> := <expr> + <expr> | <expr> - <expr> | [<number>]d(<number>|%) | <number> <number> := positive integer So e.g. d6+20-2d3 would be allowed, and should evaluate as rand.Next(1, 7) + 2...

Catmull-Rom splines in python

Hi all, Is there a library or function in python to compute Catmull-Rom spline from three points ? What I need in the end are the x,y coordinates of points along the spline, provided that they are always equidistant of a given amount t along the spline (say, the spline curve is 3 units long and I want the x,y coordinates at spline leng...

Calculate rotations to look at a 3D point?

I need to calculate the 2 angles (yaw and pitch) for a 3D object to face an arbitrary 3D point. These rotations are known as "Euler" rotations simply because after the first rotation, (lets say Z, based on the picture below) the Y axis also rotates with the object. This is the code I'm using but its not working fully. When on the groun...

Calculating permutations using a Java annotation

I'm interested in calculating permutations for parameters for something like this: public class Movie() { @Selection(minimum=1,maximum=10) public Integer setLength() {} @Selection(minimum=1.1,maximum=5.5) public Double setCost() {} } So I can write something like List getPermutations(); so that I could get a list of eve...

Creating planar shadows with 4x3 matrices?

Hi All, Was just wondering how I would go about creating a planar shadow from a 4x3 matrix, all online demos I've seen use 4x4 matrices instead. ...

Computing the probability for a section of a joint distribution

Considering I have a continuous joint distribution of two independent normal random variables (let's assume the independent vars are on the X and Z axis, and the dependent - the joint probability - is on the Y axis), and I have a line anywhere on the XZ plane, how would I compute the probability of a point falling on one side or the othe...

How do I create a Bezier curve to represent a smoothed polyline?

I have a polyline that approximates a curve, and I want to draw it as a smooth curve in PostScript, which supports Bezier curve drawing. To do that, I need to generate two control points between each pair of polyline points. (I can't get the original curve from the source, just the polyline.) I've had some success using cardinal spline...

Tinyurl-style unique code: potential algorithm to prevent collisions

I have a system that requires a unique 6-digit code to represent an object, and I'm trying to think of a good algorithm for generating them. Here are the pre-reqs: I'm using a base-20 system (no caps, numbers, vowels, or l to prevent confusion and naughty words) The base-20 allows 64 million combinations I'll be inserting potentially...

equation string in vb .net

Hello I'm trying to build a scientific calculator with vb .net, except it is vista glass :-p I basically want the user to be able to enter an equation like SQRT(5 * 6) / (2 ^ 4) and then I want vb to use system.math to solve it. If I write this in my code, vb is able to do it, so how could I do this at runtime. Thanks ...

f# whole number float modulus 1.0 = 1.0?

Ok I have two functions the first of which looks like so: let dlth x = float (x.ToString().Length) which takes a float and returns the number of digits, that part works fine. The second function looks like this: let droot x = ((x ** (1./(dlth x))) % 1.) which takes a float and raises it to a power equal to 1.0/(number of digits), ...

How calculate minimal waste when tailoring tubes

I have a rather mathematical problem I need to solve: The task is to cut a predefined number of tubes out of fixed length tubes with a minimum amount of waste material. So let's say I want to cut 10 1m tubes and 20 2,5m tubes out of tubes with a standardized length of 6m. I'm not sure what an algorithm for this kind of problem would l...

Changing a matrix from right-handed to left-handed coordinate system

I would like to change a 4x4 matrix from a right handed system where: x is left and right, y is front and back and z is up and down to a left-handed system where: x is left and right, z is front and back and y is up and down. For a vector it's easy, just swap the y and z values, but how do you do it for a matrix? ...

What's a good mathematical sets implementation in JavaScript?

Where is a good mathematical sets implementation for JavaScript? It should include efficient implementations of intersection, union, complement, and (for bonus points) the Cartesian product. No, it's not homework. I got a yubikey, it is a USB keyboard that types a sequence chosen from 16 keycodes to type a 128-bit one time password (otp...

JavaScript not comparing minimum greater than maximum number values

Why is "greater than" comparisons for number values in JavaScript not working. The example below keeps returning true even when the mini number is less than the maxi. mini and maxi are form input values. This example is using jQuery to get the values, but could easily be stripped. var mini = $('form#filterPrice input.min').val(); //eg...

A value larger than ULong? Computing 100!..

I'm trying to compute 100! and there doesn't seem to be a built-in factorial function. So, I've written: Protected Sub ComputeFactorial(ByVal n As ULong) Dim factorial As ULong = 1 Dim i As Integer For i = 1 To n factorial = factorial * i Next lblAnswer.Text = factorial End Sub ...

Knowledge required to build your own integer class?

Upon reaching a brick wall with the .Net framework's lack of a BigInteger class (yet), I've decided I'd like to develop my own as an exercise (I realize open source alternatives exist). What hoops do I need to jump through to be able to develop this? Is there any particuliar knowledge pieces that I probably wouldn't have? edit: side q...

Need help in getting the bouncing formula to work correctly.

I am creating a bouncing object that can bounce around a 2D rectangular room. I have read through the answer of the other question about using velocityX and velocityY instead of normal direction angle. OK, it sounds easier so I implement the following mathematical methods below. However, there is one difference. I required that I input a...

How does a background in math make you a better programmer?

Possible Duplicate: Is mathematics necessary for programming? Why is the above a duplicate - I academically speaking would like to know HOW mathematics helps one program so some more teaching could be put in to modern CS and engineering degrees NOT if it is necessary. A lot of my colleagues have backgrounds in Mathematics, som...

Flipping a quaternion from right to left handed coordianates

I need to flip a quaternion from right: x = left to right y = front to back z = top to bottom to left handed coordinates where: x = left to right y = top to bottom z = front to back How would I go about doing this? ...

Tuple Relational Calculus or Relational Algebra Syntax verifier?

Does anybody knows of a software package where you can type a formula and it verifies sintactically (it doesn't need to check semantics). Thanks. ...