math

3D Camera Zoom and follow physics in java?

I'm trying to make it so that no matter how far apart two objects are they'll both remain on screen. I'm using JOGL, but that shouldn't matter as I just need help with the math. This is what I have so far: float distance = (float) ((Math.sqrt((p1.x - p2.x) + (p1.y - p2.y)))); float camx = (float)((p1.x + p2.x) * 0.5); float camy = (flo...

Unsigned int to signed in php

I got a problem with ip2long in PHP5. It appears, that in 32bit OS ip2long returns signed int, and in 64bit OS unsigned int is returned. My application is working on 10 servers, and some are 32bit and some are 64bit, so I need all them to work same way. In PHP documentation there is a trick to make that result always unsigned, but since ...

Possible number of combinations for return travel routes

My math is bad, real bad. So bad I'm struggling to even phrase this question, but here goes. The situation is train travel and you have four arrays to work with. Leaving_Stations Arriving_Stations Leaving_Dates Returning_Dates So let's say you're only interested in one way routes and you need to figure out how many combinations of r...

Can anybody explain the contrapositive

I'm trying to construct a contrapositive for the following statement: If A is 0 or B is 0, then A*B is 0. Here is my attempt: If A*B is not 0, then A is not 0 or B is not 0. The original statement is true, but the contrapositive is false since both A and B must be non-zero in order for A*B to be non-zero... am I doing something wrong? ...

Project Euler Problem 245

I'm onto problem 245 now but have hit some problems. I've done some work on it already but don't feel I've made any real steps towards solving it. Here's what I've got so far: We need to find n=ab with a and b positive integers. We can also assume gcd(a, b) = 1 without loss of generality and thus phi(n) = phi(ab) = phi(a)phi(b). We are...

Fractional Part of the number question.

What is a good algorithm to determine the necessary fraction needed to add/sub to the number in order to round it to the nearest integer without using the inbuilt ceiling or floor funcitons? Edit: Looking for a mathematical number trick to figure out the part needed to round the number to the nearest integer. The more primitive the mat...

Which floor is redundant in floor(sqrt(floor(x)))?

I have floor(sqrt(floor(x))). Which is true: The inner floor is redundant. The outer floor is redundant. ...

Fastest algorithm for circle shift N sized array for M position

What is the fastest algorithm for circle shifting array for m positions? For example [3 4 5 2 3 1 4] shift m = 2 positions should be [1 4 3 4 5 2 3] Thanks a lot ...

Interview qns...Do the below without any conditional or comparison operator.

Hi All, Do the below without any conditional or comparison operator. if (Number <= 0) { Print '0'; } else { print Number; } thanks.. ...

What's the simplest way to extend a numpy array in 2 dimensions?

I have a 2d array that looks like this: XX xx What's the most efficient way to add an extra row and column: xxy xxy yyy For bonus points, I'd like to also be able to knock out single rows and columns, so for example in the matrix below I'd like to be able to knock out all of the a's leaving only the x's - specifically I'm trying to...

Drawing part of a Bézier curve by reusing a basic Bézier-curve-function?

Assuming I'm using some graphic API which allows me to draw bezier curves by specifying the 4 necessary points: start, end, two control points. Can I reuse this function to draw x percent of the 'original' curve (by adjusting the control points and the end point)? Or is it impossible? Unnecessary information, should someone care: ...

Do you have a better idea to simulate coin flip?

Right now i have return 'Heads' if Math.random() < 0.5 Is there a better way to do this? Thanks edit: please ignore the return value and "better" means exact 50-50 probability. ...

Number base conversion as a stream operation

Is there a way in constant working space to do arbitrary size and arbitrary base conversions. That is, to convert a sequence of n numbers in the range [1,m] to a sequence of ceiling(n*log(m)/log(p)) numbers in the range [1,p] using a 1-to-1 mapping that (preferably but not necessarily) preservers lexigraphical order? I'm particularly in...

Need a function to limit a line (known by its coordinates) in its length

Hello! I need a function which takes a line (known by its coordinates) and return a line with same angle, but limited to certain length. My code gives correct values only when the line is turned 'right' (proven only empirically, sorry). Am I missing something? public static double getAngleOfLine(int x1, int y1, int x2, int y2) { do...

What are eigen values and expansions?

What are eigen values, vectors and expansions and as an algorithm designer how can I use them? EDIT: I want to know how YOU have used it in your program so that I get an idea. Thanks. ...

Calculating slope in -ve, zero and +ve domains

Imagina a sine wave oscillating about a zero line. My task is to calculate the slope at several random points along the wave using a fairly coarse x axis scale. (yes this has a real application) When the wave is in +ve terrirtory (above the zero line) slope can be calculated from: Slope = (y(n) / y(n-1)) - 1 This yeilds +ve slope vla...

how to implement/calculate this function in objective c?

CUMIPMT(Rate,NumberOfPayments,PresentValue,StartPeriod,EndPeriod,Type).? plz tell me a step by step guide how this formula works. ...

SQL to select the middle third of all values in a column in PostgreSQL

Suppose I have a column of heights -- how can I select all and only those height values that are neither in the top 30% of values nor the bottom 30% of values. UPDATE: I'd like the answer for PostgreSQL (or, failing that, MySQL -- I'm using Rails). ...

What kind of logarithm functions / methods are available in objective-c / cocoa-touch?

I've tried searching for logarithm + objective-c, but all I get is math test pages from teachers, or explanations what a logarithm is ;) I've got some measurements that are like 83912.41234 and others are 32.94232. I need to press down this huge spectrum into something between 0 and 100, and that 32.94232 would habe to be at least somet...

How do I extract the angle of rotation from a QTransform?

I have a QTransform object and would like to know the angle in degrees that the object is rotated by, however there is no clear example of how to do this: http://doc.trolltech.com/4.4/qtransform.html#basic-matrix-operations Setting it is easy, getting it back out again is hard. ...