math

Double integration of acceleration from accelerometer to find position?

I am attempting to use output from an accelerometer moving back and forth on a single axis to calculate its current position. I have tried using Euler integrations, but the velocity and position errors become too large too quickly. After some reading, I am wondering whether RK4 could be applied to this problem to minimise the error? Ch...

the logarithm of quaternion

i'm reading <<3D math primer for graphics and game development>> By Fletcher Dunn and Ian Parberry, on page 170, the logarithm of quaternion is defined as log q = log([cosa nsina]) ≡ [0 an] i don't see how does log([cosa nsina]) equals to [0 an], can anyone help me out? thanks. ...

Open Source Objective-C Math/Calculator engine

Hej guys, I was wondering if you know any well working Math or Calculation engines written in Objective-C? Found a graphing one using CorePlot already.... Thanks for your help! :) ...

Why is cosine used to calculate the x values and sine the y values for an arc?

I'm trying to understand the math on this raphael.js demo: http://raphaeljs.com/pie.js Checkout the sector method: function sector(cx, cy, r, startAngle, endAngle, params) { var x1 = cx + r * Math.cos(-startAngle * rad), x2 = cx + r * Math.cos(-endAngle * rad), y1 = cy + r * Math.sin(-startAngle * rad), y2 ...

2D Collision Detection Code

Does anyone know a very simple physics engine, or just a set of basic functions that could complete these tasks: Simple point, line, and rectangle collision detection? I looked at Box2D but it is way too advanced for what I am making. I just need some simple code. Thanks in advance! ...

Statistical calculations

hi, I have a large dataset with name and values. I want to categorize all these values into a meaningful category: eg: 25% names with certain range of values fall in category 1 50% names with certain range of values fall in category 2. Tried using percentile calculation: but this ends up giving me inconsistent categorization. I was look...

Finding the sum of the digits

I've have a 5 digit integer say, int num = 23456 how to find the sum of the digits.??? ...

How to represent mathematical symbols and capture user input for the same

How do you capture user input related to mathematical fractions. Assuming I would like to present a simple square and ask the user to select 3/4ths of a square. What kind of UI control should we use to first all represent a square (with 4 equal blocks inside) and to have a mechanism to capture user input. Assuming you would like to draw...

Are there math libs for F#?

As far as I known, there are are numpy and scipy for python. Are there similar libs for F#? Thanks. ...

Math rendering library for iPhone OS

Is there a library to render mathematical equations that can be used in iPhone OS? I would be very happy with a library that renders MathML or LaTeX to a format that iPhone OS can display. If the lib were licensed under BSD (or similar), that would be perfect. ...

converting angle to radian

Hi, I got angle in degree as -415 degrees, i have converted it into radian as float degreeValue = -415 float radianValue = degreeValue * pi / 180.0; here i got as -0.7(round off) how to convert again into degree to get same value of angle in degrees. ...

Easy interview question got harder: given numbers 1..100, find the missing number(s)

I had an interesting job interview experience a while back. The question started really easy: Q1: We have a bag containing numbers 1, 2, 3, …, 100. Each number appears exactly once, so there are 100 numbers. Now one number is randomly picked out of the bag. Find the missing number. I've heard this interview question before, of cour...

PHP: Modifying prices to look presentable?

Hi everybody, We've all seen that stores have nice-looking pricing on their products; "1.99", "209.90" and so on. That's easily done as well if you enter prices manually, but l et's say that we would have a database which stores prices, that are daily updated according to currency changes. Prices are therefore automatically calculated...

Rounding a float to 1/4ths in Objective C

what's the most elegant way of rounding a float to it's closest 1/4ths in Objective C? For example: 3.14 should be 3.25 2.72 should be 2.75 6.62 should be 6.50 1.99 should be 2.00 etc. ...

Rounding down UNIX time to lower hour in PHP

I have been trying in vain to round down the current time to the lower hour in PHP. Here's what I want to do: 1. Take the current time: $time_now = time(); 2. Round it down to the closest hour: $time_now = $time_now - ($time_now % 3600); 3. Print it using the function date: print date('d m Y H:i', $time_test); But what seems to be happ...

Visiting all entries of Sparse Matrix in the org.apache.commons.math.linear package

Hi, I see 2 implementations of sparse matrix in this package. OpenMapRealMatrix SparseFieldMatrix Both are documented as "Sparse matrix implementation based on an open addressed map". Do you know what are the diffrences between the two? also, what's the best way to iterate over all entries in a fast way (which means, iterating over...

Is it irresponsible to generate new Guids "willy nilly", and if so, or not, why?

in c#, at least, generating a new guid is a one line one call process. A guid is easy to use and format, and it "guarantees" uniqueness. However, is it irresponsible to just go off and generate new guids for every little thing. Could we be significantly increasing the chances of a "ta tan tan" guid collision?! thoughts...? ...

Compress two or more numbers into one byte

Hi, I think this is not really possible but worth asking anyway. Say I have two small numbers (Each ranges from 0 to 11). Is there a way that I can compress them into one byte and get them back later. How about with four numbers of similar sizes. What I need is something like: a1 + a2 = x. I only know x and from that get a1, a2 For the...

Optimize me! (C, performance) -- followup to bit-twiddling question

Thanks to some very helpful stackOverflow users at Bit twiddling: which bit is set?, I have constructed my function (posted at the end of the question). Any suggestions -- even small suggestions -- would be appreciated. Hopefully it will make my code better, but at the least it should teach me something. :) Overview This function wil...

Find the outline of a union of grid-aligned squares

How to get the co-ordinates of the outline shape formed using smaller grid blocks. For example, If I used 32x32 unit blocks for construct a shape (any shape). Then how can I get overall co-ordinates of the shape, including the negative spaces. For example: One could arrange the blocks like this: (each block is 32x32 and coordinates ref...