math

Why does Math.floor return a double?

I was just wondering...official javadoc says that it returns a double that is "equal to a mathematical integer", but then why shouldn't it return an int? ...

Misunderstanding MixColumns step

I'm having an issue understanding the MixColumns step described here. I know about diffusion and it all makes sense up the the point where it states that each column is treated as a polynomial and multiplied modulo over GF(2^8). BUT..multiplying in GF(2^8). Although the domain is still the same, it is not reversible due to mod.... and ...

NineBlock generation

Im looking to make my own implementation of these Identicons or Gravatars found here on StackOverflow. Most questions I could found was about utilizing existing 3rd party libraries, especially those hooked with Gravatar. After some searching I stumbled upon this page. And from the looks of it, its not that hard. What needs to be rando...

LaTeX equivalent to Google Chart API

I'm currently looking at different solutions getting 2 dimensional mathematical formulas into webpages. I think that the wikipedia solution (generating png images from LaTeX sourcecode) is good enough until we get support for MathML in webbrowsers. I suddenly realized that it might be possible to create a Google Charts API equivalent fo...

How do I gracefully test for overflow situations in C#?

Update: I'm going to leave it as is: The performance hit of a exception (very rare) is better than the probably performance hit for checking on each operation (common) I'm trying to support an "EstimatedRowCount" that in one case would be the product of two sub-cursors that are joined together: estimatedRowCount = left.EstimatedRowCo...

Projecting a 3D point to a 2D screen coordinate

Based on information in Chapter 7 of 3D Programming For Windows (Charles Petzold), I've attempted to write as helper function that projects a Point3D to a standard 2D Point that contains the corresponding screen coordinates (x,y): public Point Point3DToScreen2D(Point3D point3D,Viewport3D viewPort ) { double screenX = 0d, screenY = 0...

Identify this Algorithm: Slots and Pegs

I have a number of slots and pegs arranged in a straight line. The pegs can be moved and need to be moved to a slot each. A slot can be left empty only if all pegs are taken. When a peg is moved, it is not allowed to go past another peg. In other words the order of the pegs must be maintained. Preferably, the total distance moved by all ...

Fast transcendent / trigonometric functions for Java

Since the trigonometric functions in java.lang.Math are quite slow: is there a library that does a quick and good approximation? It seems possible to do a calculation several times faster without losing much precision. (On my machine a multiplication takes 1.5ns, and java.lang.Math.sin 46ns to 116ns). Unfortunately there is not yet a way...

How to 'zoom' in on a section of the Mandelbrot set?

I have created a Python file to generate a Mandelbrot set image. The original maths code was not mine, so I do not understand it - I only heavily modified it to make it about 250x faster (Threads rule!). Anyway, I was wondering how I could modify the maths part of the code to make it render one specific bit. Here is the maths part: for...

Calculate a Ratio in C#

I thought this would be simple, but searching Google didn't seem to help. I'm basically trying to write a function which will return a ratio as a string (eg 4:3) when supplies with two integers (eg 800 and 600). string GetRatio(Int A, Int B) { // Code I'm looking for return Ratio; } Many Thanks ...

Performance of Java matrix math libraries?

We are computing something whose runtime is bound by matrix operations. (Some details below if interested.) This experience prompted the following question: Do folk have experience with the performance of Java libraries for matrix math (e.g., multiply, inverse, etc.)? For example: JAMA: http://math.nist.gov/javanumerics/jama/ COLT: ...

WPF: Translating a Canvas at an angle

With reference to this programming game I am currently building. Important: Scroll down to see [Edit] Some of the methods that a user can call in my game will be methods that will do a Translate Transform to the Robot (just a Canvas basically). From the move method, I know the heading (angle) at which the Robot will be facing at the t...

What is SVD(singular value decomposition)

How does it actually reduce noise..can you suggest some nice tutorials? ...

How to check if m n-sized vectors are linearly independent?

Disclaimer This is not strictly a programming question, but most programmers soon or later have to deal with math (especially algebra), so I think that the answer could turn out to be useful to someone else in the future. Now the problem I'm trying to check if m vectors of dimension n are linearly independent. If m == n you can just bui...

How to approximate a vector contour from an elevation raster?

I have an elevation map stored as a raster. I'd like to fit a smooth "vector" curve to the contours of constant elevation. In my application, the data are actually geographic elevations, but the problem could be generalized to any function of two variables. I can produce another raster with anti-aliased contour lines, and use that as in...

Math (in WPF): Getting new x,y coordinates after a translation

With reference to this programming game I am currently building. I am using WPF to animate canvases, and I am using the BeginAnimation method to translate (move) a canvas across another canvas. With the BeginAnimation, I need to specify the From and To coordinates for both x and y, and this is the method I am using this like such: //X...

Coordinate system Transitions

I have a game world with lots of irregular objects with varying coordinate systems controlling how objects on their surface work. However the camera and these objects can leave and move out into open empty space, where a normal Cartesian coordinate system is used. How do I manage mapping between the two? One idea I had would be to wrap ...

How can a convex polygon be broken down into right triangles aligned on the X- and Y- axes?

Given a convex polygon represented by a set of vertices (we can assume they're in counter-clockwise order), how can this polygon be broken down into a set of right triangles whose legs are aligned with the X- and Y-axes? Since I probably lack some math terminology, "legs" are what I'm calling those two lines that are not the hypotenuse ...

Use fov and center pan and tilt values to calculate boundary's pan and tilt?

I have the current fov and the center pan and tilt values. How would I calculate what the pan and tilt values are of the edges(i.e. min pan value and max tilt) with this information? ...

Solving nonlinear equations numerically

Hello, I need to solve nonlinear minimization (least residual squares of N unknowns) problems in my Java program. The usual way to solve these is the Levenberg-Marquardt algorithm. I have a couple of questions Does anybody have experience on the different LM implementations available? There exist slightly different flavors of LM, and ...