math

how to "mix" two numbers into one hex-string

How to generate a code from two numbers, that when you know this code and one of the numbers you can descramble the second number? For example you have two numbers: 983 and 2303 and you "mix" it into hex-string like this:4b17a190bce4ea32236b98dd. When you know first number and this hex-string you can descramble second number. But when yo...

How to solve homogeneous linear equations with NumPy?

If I have homogeneous linear equations like this array([[-0.75, 0.25, 0.25, 0.25], [ 1. , -1. , 0. , 0. ], [ 1. , 0. , -1. , 0. ], [ 1. , 0. , 0. , -1. ]]) And I want to get a non-zero solution for it. How can it be done with NumPy? EDIT linalg.solve only works on A * x = b where b does not...

General Formula to Calculate Polyhedron Volume

Given a list of vertices (v), and a list of edges connecting the vertices (e), and a list of surfaces that connect the edges (s), how to calculate the volume of the Polyhedron? ...

Calculating point of intersection based on angle and speed

I have a vector consisting of a point, speed and direction. We will call this vector R. And another vector that only consists of a point and a speed. No direction. We will call this one T. Now, what I am trying to do is to find the shortest intersection point of these two vectors. Since T has no direction, this is proving to be difficult...

Programming math-based images for use in high-resolution artwork

I'm interested in creating poster-sized images that contain repeating patterns, similar to the two (public domain) images below, the Flower of Life and a Penrose tiling: My questions: How do people usually create images like these on a computer? I'm hoping the answer isn't, "Open Adobe Illustrator and guess at intersection points," ...

How many digits in this base ?

The problem is to derive a formula for determining number of digits a given decimal number could have in a given base. For example: The decimal number 100006 can be represented by 17,11,9,8,7,6,8 digits in bases 2,3,4,5,6,7,8 respectively. Well the formula I derived so far is like this : (log10(num) /log10(base)) + 1. in C/C++ I use...

Count number of points inside a circle fast

Given a set of n points on plane, I want to preprocess these points somehow faster than O(n^2) (O(nlog(n)) preferably), and then be able to answer on queries of the following kind "How many of n points lie inside a circle with given center and radius?" faster than O(n) (O(log(n) preferably). Can you suggest some data structure or algo...

Simple math statements in bash in a for loop.

Hi. I'm quite new to bash scripting and usually avoid it all costs but I need to write a bash script to execute some simple things on a remote cluster. I'm having problems with a for loop that does the following: for i in {1..20} do for j in {1..20} do echo (i*i + j*j ) **.5 <--- Pseudo code! done done Can you hel...

Find 2 points on a 3d object and get their distance

Hey, Ok. So I guess thing would to be envision new york city and beijing highlighted on google earth... I'm trying to figure out how to map points onto a 3d primitive object (a sphere), get their distance via any direction by the circumference, and their distance by diameter. The points are going to be latitude and longitude coordinat...

Determining output (printing) of float with %f in C/C++

I have gone through earlier discussions on floating point numbers in SO but that didn't clarified my problem,I knew this floating point issues may be common in every forum but my question in not concerned about Floating point arithmetic or Comparison.I am rather inquisitive about its representation and output with %f. The question is ...

Multiplying by inverse matrices?

If I have a matrix which is a combination of World*View*Projection and I multiply it by the inverse of the projection does it yield the World*View matrix or something else? If not then how can I extract the World*View matrix from a World*View*Projection matrix? Thanks for any help :) ...

How to find the mathematical function defining a bezier curve

Im trying to implement a bezier curve and line segment intersection test. The closest thing my searching has turned up is to take the bezier curve (lets limit it to three control points for simplicity) find the mathematical function generating that curve and place it on origo. Then, using the function for the line segment as another func...

Implementing Wilson Score in SQL

We have a relatively small table that we would like to sort based on rating, using the Wilson interval or a reasonable equivalent. I'm a reasonably smart guy, but my math fu is nowhere near strong enough to understand this: The above formula, I am told, calculates a score for a positive/negative (thumbs up/thumbs down) voting system. ...

Dealing with Negative Numbers in Strings

I have a simple, but perplexing problem, with Math. The following code will take a number from a string (usually contained in a span or div) and subtract the value of 1 from it. .replace(/(\d+)/g, function(a,n){ return (+n-1); }); This works really well, except when we get below zero. Once we get to -1 we're obviously dealing with neg...

Implementing a audio visualizer in WPF

I wish to implement a audio visualizer widget (similar to what Winamp has) in WPF. How would I approach this problem? ...

What is "entropy and information gain"?

I am reading this book (NLTK) and it is confusing. Entropy is defined as: Entropy is the sum of the probability of each label times the log probability of that same label How can I apply entropy and maximum entropy in terms of text mining? Can someone give me a easy, simple example (visual)? ...

Minimising distance: distance formula

I am writing a program in C. I want to find a solution by minimizing expression D1+D2+......+Dn where Di's are distances calculated by distance formula between 2 points. The above expression is in x & y variables Now I will differentiate this expression and find the solution. My doubt is: since in the above expression, all Di's will...

Formula for a curve (algebra in javascript)

I need an exponential equation with the following parameters: When x = 0, y = 153. When x = 500, y = 53. Y should increase exponentially as X approaches 0 and should decrease exponentially when X approaches 500. For some reason I can't remember how to do this. I'm sure once I see the equation (or one similar) I can figure out the rest....

Simple Problem - Velocity and Collisions

Okay I'm working on a Space sim and as most space sims I need to work out where the opponents ship will be (the 3d position) when my bullet reaches it. How do I calculate this from the velocity that bullets travel at and the velocity of the opponents ship? ...

Optimizing a pinhole camera rendering system

Hello, I'm making a software rasterizer for school, and I'm using an unusual rendering method instead of traditional matrix calculations. It's based on a pinhole camera. I have a few points in 3D space, and I convert them to 2D screen coordinates by taking the distance between it and the camera and normalizing it Vec3 ray_to_camera = (...