In an X and Y axis I have a field constrained by a min and a max curve. Within that field there can be an infinite amount of potential curves. I need to predict how the curve crossing a given x,y point within that field will look like.
In the image above the orange curves cross given x,y points (blue, grey, purple).
My base data is basically a collection (~100) of the following set:
A given x (double)
A given y (double)
The cross curve's x values as an array of doubles
The cross curve's y values as an array of doubles
How can I model this in accord.NET to predict a curve within this field for any x,y?
Which algorithm(s) from the library should I use to achieve my goal?
Related
We have a monitoring application that can monitor in intervals like 5 minutes, 15 minutes, 1 hour, etc. That's represented on the x-axis; The y-axis is also scalable and have values like 1.2345 - 1.5567 or can be switched to values like 26000 - 30000, etc.
Once the scale is set on the x and y axis, they don't dynamically change without a whole complete data refresh.
That being said, we only want certain people to be notified depending on the clock angle, of say, the last 5 intervals along the y axis.
The clock angles will never go counter-clockwise past 0/12; likewise, they'll never go past 6 clockwise.
I know the 3 o'clock angle is obvious when the x axis value is exactly the same as it was 5 intervals ago.
But how does one even start coding for everything in between? I can get the differences in x values easily (in the example graphic below, it's 0.3), and the difference in the y-axis in the below graphic is 4.
So with trigonometry that's opposite over adjacent, which means a tan operation I believe? If so, 0.3/5 doesn't seem to yield any values that seem like a clock angle.
Since I can't get any farther than that, I have no idea how it would be coded in C# other than calculating the differences.
Any help would be greatly appreciated!
You should be using atan2 (wiki , docs)
From the wiki:
atan2(y, x) returns the angle θ between the ray to the point (x, y) and the positive x axis, confined to (−π, π]
Note that the result is in radians, so you need to convert it if you want degrees
As stated, one radian is equal to 180/π degrees. Thus, to convert from radians to degrees, multiply by 180/π.
A couple of things here. First I think what you are asking for is the angle φ below, given two data points (x1,y1) and (x2,y2).
The problem here is that the angle is measuring the indicated triangle in pixels and not in x, y units.
So it is incorrect to do var φ = Math.Atan( (y2-y1)/(x2-x1) ); because the x and y axis have different units and angles are always dimensionless.
What additional information is needed, is the size of the graph area in pixels, as well as the range of values. Alternatively, the scaling gx,gy in pixels/unit for both axis.
For example, if the x-axis needs 45 pixels to span 1 grid of 1 hour (60 minutes) then te scaling is double gx = 45/60.0, and if the y-axis needs also 45 pixels to span 1 grid of 0.1 value then double gy = 45/0.1.
Then you can use this to calculate the sides of the triangle in pixels before calculating the angle
var adjacent = gx*(x2-x1); // convert x-axis units to pixels
var opposing = gy*(y2-y1); // convert y-axis units to pixels
var φ = Math.Atan(addjacent/opposing) * (180/Math.PI);
The last part calculates the angle φ and converts it from radians to degrees.
I have array of 4 points and I want to check whether these points will create a rectangle or not. If it will create a rectangle than calculate area of this.
x,y value of point can be positive or negative or mix of it.
You can calculate the six distances between the four points.
Use Pythagoras for this.
If they result in three pairs of equal non-zero distances it is a rectangle.
The product of the shorter two is its area.
Make sure not to fall into rounding error traps; so use an epsilon criterion when comparing for 'equality' as floating point numbers have a tendency to not be equal even if they should be mathematically!
I'm working with a mounted industrial CCD camera and I have no information about its parameters. When an image is taken programmatically over WinUSB, the result in figure 1 is received. What you will notice is that the gaps between the lines differ greatly in the image. This is not the case in the actual image.
I have a technique for determining the location of the lines and have a list of pixel coordinates for where the lines must occur in a non-distorted image.
So I have
The pixel coordinate of the lines when the image is taken
The pixel coordinates of where the lines should be
What I need to do
Use these values to apply to every subsequent image taken with the camera, so that
each image is corrected.
However, I am pretty stuck on exisiting techniques which follow this approach. I know many algorithms exist on the internet which either make use of lens parameters or a strength parameter, but these techniques aren't very suitable in my scenario. The parameters aren't known and adjusting a strength value by the eye is not accurate enough.
Any pointers on techniques would be of great help; as I'm currently at a loss.
Figure 1. Distorted image taken by fixed location CCD camera
Hum, can you explain why the standard calibration techniques aren't suitable? You don't need to know the "true" camera parameters, but you do need to estimate the linear (actually, affine) part of the distortion, which is almost the same thing.
Explanation: assuming you are dealing with a plain old spherical-like lens, the first model I'd try for your case is a two-parameter radial distortion of the form:
X = f * |x - c|
Y = k1 * X^2 + k2 * X^4
y = c + Y / f
where
x = (u, v) are the distorted pixel coordinates;
c = (cu, cv) is an unknown center of distortion (i.e. the place in the image with zero
distortion, usually on (or very close to) the lens's focal axis.
|x -c| is the radial distance of x from c in the distorted image
f is an unknown scale factor
X is the location of the distorted pixel in scaled-centered coordinates
k1 and k2 are unknown distortion coefficients
Y is the undistorted pixel in scaled-centered coordinates
y is the undistorted pixel, located on the same radius c->x as x, at a distance Y/f from c.
So your unknowns are cu, cv, f, k1 and k2. It's starting to look like a camera calibration problem, isn't it?
Except you don't really need to estimate a "true" focal length f, since (I assume) you are not interested in computing rays in 3D space. So you can simplify the problem by assigning f as the value that makes the diameter of your data point distribution equal to, say, 2, so that all the centered-scaled points X will have coordinates no larger than 1.0 in absolute value. This helps in two ways: it improves the numerical conditioning of the problem, and drops the number of unknowns to 4.
You can usually initialize the estimation by using the center of your image for c, and zero values for k1 and k2, plug your data in your favorite least-squares optimizer, run, get the solution for the unknowns, and verify that it makes sense (on additional independent images). Rinse and repeat until you get something satisfactory.
Note that you can enrich the data set used for the estimation by using more than one image, assuming, of course, that the lens parameters are constant.
I have a number of non-coplanar 3D points and I want to calculate the nearest plane to them (They will always form a rough plane but with some small level of variation). This can be done by solving simultaneous linear equations, one for each point, of the form:
"Ax + By + Cz + D = 0"
The problem I'm having at the moment is twofold.
Firstly since the points are 3D floats they can't be relied on to be precise due to rounding errors.
Secondly all of the methods to solving linear equations programatically that I have found thus far involve using NXN matrices which severely limits what I would be able to do given that I have 4 unknowns and any number of linear equations (due to the variation in the number of 3D points).
Does anyone have a decent way to either solve the simultaneous linear equations without these constraints or, alternatively, a better way to calculate the nearest plane to non-coplanar points? (The precision of the plane calculation is not too much of a concern)
Thanks! :)
If your points are all close to the plane, you have a choice between ordinary least squares (where you see Z as a function of two independent variables X and Y and you minimize the sum of squared vertical distances to the plane), or total least squares (all variables independent, minimize the sum of normal distances). The latter requires a 3x3 SVD. (See http://en.wikipedia.org/wiki/Total_least_squares, unfortunately not the easiest presentation.)
If some of the points are outliers, you will need to resort to robust fitting methods. One of them is RANSAC: choose three points are random, build their plane and compute the sum of distances of all points to the plane, as a measure of fitness. Keep the best result after N drawings.
There are numerical methods for linear regression, which calculates the nearest line y=mx+c to a set of points. Your solution will be similar, only it has one more dimension and is thus a "planar regression".
If you don't care the mathematical accuracy of the algorithm and just want to get a rough result, then perhaps you'd randomly 3 points to construct a plane vector, then adjust it incrementally as you go through the rest of the points. Just some thoughts...
Bit of a weird one this. I'm rendering datasets on a map and need to split out points that have exactly the same long and lat. I had the idea of grouping my dataset by long and lat and where they are the same adjusting slightly so that they are visible as seperate entities on the map - rather than overlapping.
I'm using linq to group them and then enumerating my grouped items and I'd like to spiral the adjusted points around the orginal point (this is a requirement as I may have a few hundred points that are the same geographically) so that they spread out from the original point.
Does anyone know of a simple calculation i can add to my loop to adjust the items in this manner.
Thanks,
The math behind this is pretty simple. A circle can be represented by the sine function in the x-axis and the cosine function in the y-axis. Here's some pseudo-code:
int num = OverlappingPoints.Length;
for(int i = 0; i < num; ++i)
{
int radius = 50;
// using 2*pi because most math functions use radians... change 2*pi to 360 if your math library uses 360 degrees instead of 2*pi radians to represent a circle.
Map.Plot(OverlappingPoints[i].Latitude + radius*sin(2*pi*i/num),
OverlappingPoints[i].Latitude + radius*cos(2*pi*i/num));
}
That pseudo-code, if properly implemented, will draw the points out in a circle around the original point. Change the radius multiplier to the sine and cosine functions if you want to increase the radius of the circle. If you want the points to spiral out instead of making a circle, choose a number of points per circle revolution and replace num with that number in the sin/cos functions. Also, increase the radius after each loop iteration, probably by using a number and multiplying it by the loop index. (i.e. you could change radius to 50*i).
Hope this helps.