math

Calculate overlap between two rectangles on x/y grid?

I need to calculate the overlap (amount or yes/no) that two rectangles make on a special x/y grid. The grid is 500x500 but the sides and corners connect (are continuous). So the next point after 499 becomes 0 again. In a previous question I asked for a way to calculate the distance between two points in this grid. This turned out to be ...

Need help with circle collision and rotation? - Game Physics

Ok so I have bunch of balls: What I'm trying to figure out is how to make these circles: Rotate based on the surfaces they are touching Fix collision penetration when dealing with multiple touching objects. EDIT: This is what I mean by rotation Ball 0 will rotate anti-clockwise as it's leaning on Ball 3 Ball 5 will rotate ...

How can I generate random samples from bivariate normal and student T distibutions in C++?

Hi, what is the best approach to generate random samples from bivariate normal and student T distributions? In both cases sigma is one, mean 0 - so the only parameter I am really interested in is correlation (and degrees of freedom for student t). I need to have the solution in C++, so I can't unfortunately use already implemented funct...

Basic imperial conversion problem

Coding a calculation tool for my android. On of the inputs is distance in Feet and Inches. I have two inputs (input3 and input4) for feet and inches, respectively. In my calculation I am trying to convert these two inputs to a decimal number to be used in the rest of the equation. Here's the part of my code that does this: private void...

How can I calculate individual point masses?

I am working on a C# 2d soft body physics engine and I need to assign masses to an object's vertices given: a list of vertices (x,y positions), the total mass for the object, and the center of mass. The center of mass is given as: where, R = center of mass M = total mass mj = mass of vertex j rj = position of vertex j I need an al...

Java Clustering Library

Hi All, Thanks for reading my question. I am looking for a light weight clustering library in java. I don't need 100s of clustering algo in that library just 5 to 7 algo would be fine for me. I am sure, you are going to ask. What kind of algo. do you need and for what purpose :). So here is the answer. I just need to do classification o...

Simple MATLAB/Octave simulation

This should be a very simple question for anyone who has some experience in this area, but I'm still new to this. I have the following system (or here is an image with better resolution): Given the following input: u = min(2 - t/7.5, 2*(mod(t, 2) < 1)); I need to plot the output of system y. I am describing the system with the fo...

How Many Combinations In This If Statement

Ok - I have someone I work with who has written somthing like this if() if() if() if() if() I dont like this!! If there are ten different boolean flags how many combinations are there? 10 factorial? I am trying to explain why this is bad ...

Update position of a point

Hi all. My problem is this: I have a set of points in 3D space, and their positions are updated from time to time with a certain velocity. But i need to keep a minimal distance between them. Can you help me with this? EDIT: I am using C for the implementation of the algorithm. Thanks in advance. ...

What is the best algorithm to calculate the most scored item?

I have an music items that are scored by users between 1 to 5, and I need a formula to get the 5 most scored items. But obviously an item that get 3.5 average score from 1000 different users will be more scored then an item thet get 4.9 average score from only 5 users... in other words I think that if an item get attention from people ...

App crashes when calling Spinner value in calculation?

import android.app.Activity; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.Spinner; import android.widget.SpinnerAdapter; import android.widget.Text...

Compute union of two arbitrary shapes

I'm working on an application, I need to be able to combine two overlapping arbitrary shapes as drawn by the user. This would be a Union operation on the two shapes. The resultant shape would be the silhouette of the two overlapping shapes. The shapes are stored as a sequence of points in a clockwise manner. Ideally I'd like an algorit...

Java maths - testing for NaN

I would like to have some kind of project-wide fail fast mechanism (maybe a RuntimeException) for any code that causes assignment of NaN. In my project NaN is never a valid value. I realise I could add asserts (using isNaN) or other tests throughout but I want to know if there is a more elegant way. ...

Select random k elements from a list whose elements have weights

Selecting without any weights (equal probabilities) is beautifully described here. I was wondering if there is a way to convert this approach to a weighted one. I am also interested in other approaches as well. Update: Sampling without replacement ...

.NET: Decimal to rounded string

If I have a decimal, how do I get a string version of it with two decimal places? This isn't working: Math.Round(myDecimal, 2).ToString("{0.00}"); ...

Function for returning a list of points on a Bezier curve at equal arclength

Someone somewhere has had to solve this problem. I can find many a great website explaining this problem and how to solve it. While I'm sure they are well written and make sense to math whizzes, that isn't me. And while I might understand in a vague sort of way, I do not understand how to turn that math into a function that I can use....

Write a truly inclusive random method for javascript

Javascript's MATH object has a random method that returns from the set [0,1) 0 inclusive, 1 exclusive. Is there a way to return a truly random method that includes 1. e.g. var rand = MATH.random()*2; if(rand > 1) { rand = MATH.floor(rand); } return rand; While this always returns a number from the set [0,1] it is not truly ran...

How to calculate translate while zooming in WPF/Surface

I'm doing a surface app where I need to scale my scene (zoom) while the user scales with their fingers (i.e pinching) Currently I have it working ok, but the issue is that I need to zoom in on the center point between the users fingers. I have the point, but the maths behind the translation is hard to grasp. When I apply a ScaleTransf...

3d Parabolic Trajectory

Hi, I'm trying to figure out some calculations using arcs in 3d space but am a bit lost. Lets say that I want to animate an arc in 3d space to connect 2 x,y,z coordinates (both coordinates have a z value of 0, and are just points on a plane). I'm controlling the arc by sending it a starting x,y,z position, a rotation, a velocity, and a...

Shortest route to intersection

I asked this question about 2 months ago but found none of the answers to be helpful enough. So I am giving it another shot. I think it was my fault not describing it well enough. So lets try again. Here is a rough idea of what I am trying to accomplish. The goal is to send a projectile from point T to intercept the object represente...