math

Intersection of a line - game development

I am creating a game where I want to determine the intersection of a single line. For example if I create a circle on the screen I want to determine when I have closed the circle and figure out the points that exist within the area. Edit: Ok to clarify I am attempting to create a lasso in a game and I am attempting to figure out how I c...

Possible Loss of Fraction

Forgive me if this is a naïve question, however I am at a loss today. I have a simple division calculation such as follows: double returnValue = (myObject.Value / 10); Value is an int in the object. I am getting a message that says Possible Loss of Fraction. However, when I change the double to an int, the message goes away. Any t...

position spheres along a bezier curve

I am trying a couple of tutorials from http://nehe.gamedev.net, in order to learn openGL programming, I would like to position spheres along a Bezier curve such that they appear as a string of pearls. how can I position such spheres along the curve. I am drawing the curve using de Casteljau's algorithm and hence can get the XYZ points on...

Percentages and trees

Hi, I have an unordered tree. Each node represents a task that can be done (1), not done (0) or have children tasks. For example: 1 -1.1 -1.2 --1.2.1 --1.2.2 -1.3 2 3 -3.1 4 -4.1 --4.1.1 5 Suppose that the leaves 1.2.1, 3.1 and 5 are done 1 -1.1 -1.2 --1.2.1* --1.2.2 -1.3 2 3 -3.1* 4 -4.1 --4.1.1 5* I want to calculate the percen...

Excel RoundUp vs .NET Math.Round

Guys, in Excel, =ROUNDUP(474.872126666666, 2) -> 474.88 in .NET, Math.Round(474.87212666666666666666666666667, 2, MidpointRounding.ToEven) // 474.87 Math.Round(474.87212666666666666666666666667, 2, MidpointRounding.AwayFromZero) // 474.87 My client want Excel rounding result, is there any way I can get 474.88 in .NET? Thanks a lot ...

ublas vs. matrix template library (MTL4)

I'm writing a software for hyperbolic partial differential equations in c++. Almost all notations are vector and matrix ones. On top of that, I need the linear algebra solver. And yes, the vector's and matrix's sizes can vary considerably (from say 1000 to sizes that can be solved only by distributed memory computing, eg. clusters or sim...

How do I determine the number of decimal digits of an integer in C?

for instance, n = 3432, result 4 n = 45, result 2 n = 33215, result 5 n = -357, result 3 I guess I could just turn it into a string then get the length of the string but that seems convoluted and hack-y. ...

How do you put text below other text?

I need to write the expression meaning optimize over the parameter set. I think I should write something like $\arg \max_{\substack{w \\ \phi}} f(w,\phi)$ but this puts the subscript below at the right of \max and I'd like to put those subindexes below and centered on the max word. Which command should I use? Thanks in advance. ...

How do I set the upper and lower bounds of a dynamic graph?

Say I want to display a graph of today's stock market. I gather all my data, and I go to display the graph...is there a well known formula to set the upper and lower bounds to? Do I need to factor in all the data on the stock market from the last year to get some context? In some ways this is a design/math question, but essentially, I ...

Does anyone know how to do an "inverse" trilinear interpolation?

Trilinear interpolation approximates the value of a point (x, y, z) inside a cube using the values at the cube vertices. I´m trying to do an "inverse" trilinear interpolation. Knowing the values at the cube vertices and the value attached to a point how can I find (x, y, z)? Any help would be highly appreciated. Thank you! ...

Circle line collision detection

I have a line from A to B and a circle positioned at C with the radius R. This is in two dimensions. Which is a good algorithm to use to check whether the line intersects the circle? And at what coordinate along the circles edge it occurred? ...

How does Excel determine the axis values for charts ?

When Excel determines the axis values it will use to represent your data in a chart, the values are 'evenly distributed'. For Example: If you plot the following series in an Excel Line Chart. [0.22,0.33,0.44,0.55,0.66,0.77,0.88,0.99,1.1,1.21,1.32,1.43,1.54,1.65,1.76,1.87,1.98,2.09,2.2] Excel determines that the y-axis values should be [...

Inverse 3D (triangle) projection

Hello, I have a 3D math problem which I just can't seem to solve. I have data of 3 points. The data is a (2D) coordinate on a plane, floating somewhere in 3D space. I also know the (2D) coordinate of the projection. That results in the following array of data: [[[x1,y1], [px1,py1], [[x2,y2], [px2,py2], [[x3,y3], [px3,py3]] Where t...

OR-multiplication on big integers.

Multiplication of two n-bit numbers A and B can be understood as a sum of shifts: (A << i1) + (A << i2) + ... where i1, i2, ... are numbers of bits that are set to 1 in B. Now lets replace PLUS with OR to get new operation I actually need: (A << i1) | (A << i2) | ... This operation is quite similar to regular multiplication for ...

Digital Filter, Math in Java,

Hi, I need your help, and thank you for reading my question! I am currently writing a java Programm that will use an Direket Form 2 Transposed Filter. I know that the function filter in Matlab will do that just fine, but i have to use Java. So does anyone know you to implement this Direkt Form 2 Transposed , this Math Function: y(n) ...

Equidistant points across a cube

I need to initialize some three dimensional points, and I want them to be equally spaced throughout a cube. Are there any creative ways to do this? I am using an iterative Expectation Maximization algorithm and I want my initial vectors to "span" the space evenly. For example, suppose I have eight points that I want to space equally in...

Determing longest repeating cycle in a decimal expansion

Today I encountered this article about decimal expansion and I was instantaneously inspired to rework my solution on Project Euler Problem 26 to include this new knowledge of math for a more effecient solution (no brute forcing). In short the problem is to find the value of d ranging 1-1000 that would maximize the length of the repeating...

2D vector projection in Python

The code below projects the blue vector, AC, onto the red vector, AB, the resulting projected vector, AD, is drawn as purple. This is intended as my own implementation of this Wolfram demonstration. Something is wrong however and I can really figure out what. Should be either that the projection formula itself is wrong or that I mistake...

Mod of negative number is melting my brain!

Duplicate of Weird Objective-C Mod Behavior I'm trying to mod an integer to get an array position so that it will loop round. Doing i % arrayLength works fine for positive numbers but for negative numbers it all goes wrong. so i need an implementation of int GetArrayIndex(int i, int arrayLength) such that GetArrayIndex(-4, 3) == 2...

How do I filter data without losing shape?

Is there a filtering algorithm that converges at some shape? My problem is that I am filtering a two dimensional graph, and applying filtering repeatedly. I'm down-sampling data and re-sampling it using gaussian filters (footprints), but the graph changes its shape with every subsequent filtering. What I need is to achieve some final sha...