math

Given a bounding box and a line (two points), detemine if the line intersects the box

Title basically says it all. Given a bounding box, with definitions like bounds.min.(x/y/z), bounds.max.(x/y/z), and two points in 3D space (expressed as Vector3 objects), how can I determine if the line made by the two points intersects the bounding box? The language is C#, v2.0. ...

Why is 0 divided by 0 an error?

I have come across this problem in a calculation I do in my code, where the divisor is 0 if the divident is 0 too. In my code I return 0 for that case. I am wondering, while division by zero is generally undefined, why not make an exception for this case? My understanding why division by zero is undefined is basically that it cannot be r...

Please help me out with sine and cosine.

Hello, I know that sin is opposite/hypotenuse in a right angled triangle and cos is adjacent/hypotenuse. But when i come across functions like for Eg. In Flash :- something.x = Math.cos(someNumber) * someotherNumber; something.z = Math.sin(someNumber) * someotherNumber; what does it actually do? My stack overflows when i see such thi...

How to calculate indefinite integral programmatically

I remember solving a lot of indefinite integration problems. There are certain standard methods of solving them, but nevertheless there are problems which take a combination of approaches to arrive at a solution. But how can we achieve the solution programatically. For instance look at the online integrator app of Mathematica. So how do...

Open source alternative to Mosek?

Is there an open source alternative to Mosek? Basically, I'm looking for large scale convex optimization solver packages. Thanks! EDIT: Forgot to mention earlier, problem is non-linear; mostly quadratic, but occasionally may need non-quadratic constraints + non-quadratic objective ...

Fixed point combinators for functions over custom types?

Most examples of the use of fixed point combinators involve functions that take integers to integers (e.g. factorial). In many cases the fixed point of a function over the real numbers will end up being an arbitrary rational or perhaps irrational number (a famous example is the logistic map http://en.wikipedia.org/wiki/Logistic_map). In ...

Algorithm to locate local maxima

I have data that always looks something like this: I need an algorithm to locate the three peaks. The x-axis is actually a camera position and the y-axis is a measure of image focus/contrast at that position. There are features at three different distances that can be in focus and I need to determine the x-values for these three poi...

How to get new rectangle value when x and y axis increase....

Hi, I have a rectangle say (150, 200, 25,25) and x- axis up to 800 and y-axis upto 650. Now like to increase the value of x and y axis by 100. The rectangle value also increase according to x and y axis. say my rectangle are in the shaded place. now i increase the x and y axis. the shaded position also increases. the rectangle value al...

How to detect a trend inside unsteady data (e.g. Trendly)?

I was wondering what kind of model / method / technique Trendly might use to achieve this model: [It tries to find the moments where significant changes set in and ignores random movements] Any pointers very welcome! :) ...

$n = 2; 10-$n = 87...

hi there, well this is what i am doing: $total = (array_sum($odds))+$evens; $total = str_split($total); echo 'total[1]: '.$total[1].'<br />'; echo '10-$total[1]: ' . (10-($total[1])); and the output is: total[1]: 2 10-$total[1]: 87 my guess is it is being treated as a string, but how do i fix it? so, what i want to know is wh doe...

Optimizing an inner loop calculation in Mathematica

Hi all, I'm currently doing some computation in Mathematica related to Quantum Mechanics. As we've moved from a 1D to 2D lattice model, the problem size is becoming problematic Currently, we have a summation that looks something like this: corr[r1_, r2_, i_, j_] = Sum[Cos[f[x1, x2] Angle[i] r1 + f[y1, y2] Angle[j] r2], {x1, HL}, {x2, H...

What is required in order to implement a geo-spatial/proximity search?

I want to better understand what is required in order to implement a geo-spatial (aka proximity) search. I'd appreciate clarification on the following: Beyond the latitude & longitude for corresponding zip codes, what if anything, is required? Can anyone recommend any resources (books, websites, etc.) for understanding the formulas ...

Is this how rotation about a point is done?

Let's say I have a polygon with points: (0,0) (100,0) (100,100) (0,100) Lets also let it's center be (50,50). To rotate it would I add 50 to each component of each point, then do x' = cos(theta)*x - sin(theta)*y y' = sin(theta)*x + cos(theta)*y Then subtract 50 from each component of each point? Thanks ...

Scaling a polygon toward an edge?

I know that to scale verticies I simply have to multiply by a scale factor. But I noticed that most vector drawing applications show the shapes bounding box and by dragging one of the edge it will scale the geometry toward the opposite edge, then if you go past this edge it will end up mirroring the geometry on that axis. How is scaling ...

How to compute viewport from scrollbar?

This is probably straight forward enough but for some reason I just can't crack it (well actually its because I'm terrible at maths sadly!). I have a viewport that shows 800 pixels at a time and I want to move it left and right over a virtual number of pixels say 2400 pixels wide. I use the relative position of a scrollbar (0-1) to det...

Force CALayer's rotation direction?

Hi guys, This one has been driving me nuts... Considering "plane" is a CALayer, I rotate it in the X axis: plane.transform = CATransform3DMakeRotation(180 * M_PI / 180.0f, 1.0f, 0.0f, 0.0f); And this makes it rotate clockwise, which is perfect. Now, at some point in time, I want it to return to 0 degrees, so I use: plane.transform...

enumerate grouped columns vertically

If I have a matrix that is iterated horizontally and then vertically it would enumerate like this: 0 1 2 3 4 5 6 7 8 9 ------------------------------ 0 | 1 2 3 4 5 6 7 8 9 10 1 | 11 12 13 14 15 16 17 18 19 20 2 | 21 22 23 24 25 26 27 28 29 30 if I want to enumerate vertically I could do this: total_rows * ...

My bit logic is too outdated. Refresher needed

It's been a while since my assembly class in college (20 years to be exact). When someone gives you a number, say 19444, and says that X is bits 15 through 8 and Y are bits 7 through 0... how do I calculate values of X and Y? I promise this is not homework, just a software guy unwisely trying to do some firmware programming. ...

Convert mathematical string to int

Is there an easy way to take a String such as "5*4" and return 20? ...

how to define following operator/function in python ?

i am new to programming need to define operator/function s^m such that s^m(a^g^n+b^g^o+c^g^p*d^g^q)+a^g^f=a^g^(n+m)+b^g^(o+m)+c^g^(p+m)*d^g^(q+m)+a^g^f a b c d g ..all symbols ^=power ,in simple language operator which will transform all 'g's in bracket to g^m while keeping those out of bracket as it is . i am working on solving ...