Highcharts - Get x Value From Y value - highcharts

How can i get the x value by providing an y value between two points (an y value which is not in the data).
I have looked for an answer but i can only loop over the points which are present in the data: http://jsfiddle.net/royzcfed/
$('#button').click(function(){
y1=$('#input').val();
var points = $('#container').highcharts().series[0].points;
for (var i = 0; i < points.length; i++) {
if (points[i].y == y1){
xValue = points[i].x;
alert(xValue);
break;
}
}
});

This is a much larger question than you might be thinking.
It is certainly beyond the scope of Highcharts, and relates more to math in general. (ie Highcharts doesn't plot out each pixel, it tells the browser to draw a line between two points)
Some things to consider:
1) given that we don't seem to be talking about a specific distribution function, you would have to specify the two points between which you are trying to find your value. Otherwise, that y value could potentially fall anywhere on the chart and there is no way to correlate it to a specific x value.
2) the line between those two points would have to be a straight line, or one that follows a specific formulaic curve
3) if it is not a straight line, you will need to have the calculations that built the curve, and use them to locate your y and it's x. If it is a straight line you need to calculate slope and intercept given the two points you are working with, and work from there (look into calculating linear regression)

Related

Feature Scaling with Octave

I want to do feature scaling datasets by using means and standard deviations, and my code is below; but apparently it is not a univerisal code, since it seems only work with one dataset. Thus I am wondering what is wrong with my code, any help will be appreciated! Thanks!
X is the dataset I am currently using.
mu = mean(X);
sigma = std(X);
m = size(X, 1);
mu_matrix = ones(m, 1) * mu;
sigma_matrix = ones(m, 1) * sigma;
featureNormalize = (X-mu_matrix)/sigma;
Thank you for clarifying what you think the code should be doing in the comments.
My answer will effectively answer why what you think is happening is not what is happening.
First let's talk about the mean and std functions. When their input is a vector (whether this is vertically or horizontally aligned), then this will return a single number which is the mean or standard deviation of that vector respectively, as you might expect.
However, when the input is a matrix, then you need to know what it does differently. Unless you specify the direction (dimension) in which you should be calculating means / std, then it will calculate means along the rows, i.e. returning a single number for each column. Therefore, the end-result of this operation will be a horizontal vector.
Therefore, both mu and sigma will be horizontal vectors in your code.
Now let's move on to the 'matrix multiplication' operator (i.e. *).
When using the matrix multiplication operator, if you multiply a horizontal vector with a vertical vector (i.e. the usual matrix multiplication operation), your output is a single number (i.e. a scalar). However, if you reverse the orientations, as in, you multiply a vertical vector by a horizontal one, you will in fact be calculating a 'Kronecker product' instead. Since the output of the * operation is completely defined by the rows of the first input, and the columns of the second input, whether you're getting a matrix multiplication or a kronecker product is implicit and entirely dependent on the orientation of your inputs.
Therefore, in your case, the line mu_matrix = ones(m, 1) * mu; is not in fact appending a vector of ones, like you say. It is in fact performing the kronecker product between a vertical vector of ones, and the horizontal vector that is your mu, effectively creating an m-by-n matrix with mu repeated vertically for m rows.
Therefore, at the end of this operation, as the variable naming would suggest, mu_matrix is in fact a matrix (same with sigma_matrix), having the same size as X.
Your final step is X- mu_sigma, which gives you at each element, the difference between x and mu at that element. Then you "divide" with the sigma matrix.
Here is why I asked if you were sure you should be using ./ instead of /.
/ is the matrix division operator. With / You are effectively performing matrix multiplication by an inverse matrix, since D / S is mathematically equivalent to D * inv(S). It seems to me you should be using ./ instead, to simply divide each element by the standard deviation of that column (which is why you had to repeat the horizontal vector over m rows in sigma_matrix, so that you could use it for 'elementwise division'), since what you are trying to do is to normalise each row (i.e. observation) of a particular column, by the standard deviation that is specific to that column (i.e. feature).

Extending a straight line

There is a sloping LineSeries with two points showing a straight line. How can I calculate the Y value so the line continues infinitely in the same direction?
This line is like a guide-line that should follow along when values are added to another Series in the same chart. But must never change angle.
I'm using Delphi and Lazarus.
Suppose that the line passes through (x0,y0) and (x1,y1). The slope of the line k is given by:
k = (y1-y0) / (x1-x0)
So the line can be expressed as
y(x) = y0 + k(x-x0)
So you need to add points to the series whose x values are the minimum and maximum x values displayed on the chart. And whose y values are calculated as above.
This assumes that the line is not vertical, that is that x0 does not equal x1. If the line is vertical then the solution is trivial. Place points at the y values of the minimum and maximum values of the chart.

how to calculate number of point between three points for curve drawing?

i have three points in 2D and I want to draw a spline curve passing through them. How do I calculate the middle point (x1 and y1 as in quadTo)? i want to implement free curve like denon eq curve
For the first segment of the curve, you can probably use addQuadCurveToPoint, picking a control point with the same y value as the second point (and I picked an x value half way between the two end points):
For the second portion of the curve, you can't use quad curve, because you need two control points (or, you'd have to break it up into two quad curves, which is more hassle than its worth, IMHO). So use addCurveToPoint, using control point y values that are the same value as the y value of the point to which the control point refers (and, again, I picked x values half way between the x values of the two end points):
There are lots of permutations of this idea, but I hope this illustrates the concept. I'd suggest you start playing around with UIBezierPath and addCurveToPoint until you achieve the desired effect.

iOS convert a region defined in polar coordinates to an NxN matrix

Ok, so the situation is that I want to create an NxN matrix representing the pixels of a bitmap image.
Then, I want to change the value of all those pixels which fall in a certain region to a constant value.
The region is defined using polar coordinates.
For example,
let the matrix represent a 2048x2048 pixel bitmap, and the region be defined by 25<=r<200, 0<=theta<π/4, and I want to set the value of all those points that fall in that region to some constant, k (defined elsewhere).
What's the best way to go about this?
Should I look at any of Apple's libraries, such as vImage, or parts of the Accelerate framework, etc,
or is this something so specific that I'll have to tackle it by hand, going over each pixel in my NxN matrix to see if it lies in the region of interest?
It seems like there has to be a more efficient way to do it than just hard coding a couple of for loops. Especially if the region had some arbitrary definition, say a squiggly loop drawn by a user.
Advice?
Accelerate Framework provides a lot of functions for working with images.
In your case I'd recommend vImage Framework, which has vImageTableLookUp_* functions for image transformation using lookup tables.
For example, if red values from 25 to 200 should be constant number, you create an array
int red[256];
for (int i = 0; i < 256; i++) {
if (i >= 25 && i < 200) {
red[i] = MY_CONSTANT_VALUE;
} else {
red[i] = i;
}
}
and pass that array to the function above.

Math/OpenGL ES: Draw 3D bezier curve of varying width

I've been working on a problem for several weeks and have reached a point that I'd like to make sure I'm not overcomplicating my approach. This is being done in OpenGL ES 2.0 on iOS, but the principles are universal, so I don't mind the answers being purely mathematical in form. Here's the rundown.
I have 2 points in 3D space along with a control point that I am using to produce a bezier curve with the following equation:
B(t) = (1 - t)2P0 + 2(1 - t)tP1 + t2P2
The start/end points are being positioned at dynamic coordinates on a fairly large sphere, so x/y/z varies greatly, making a static solution not so practical. I'm currently rendering the points using GL_LINE_STRIP. The next step is to render the curve using GL_TRIANGLE_STRIP and control the width relative to height.
According to this quick discussion, a good way to solve my problem would be to find points that are parallel to the curve along both sides taking account the direction of it. I'd like to create 3 curves in total, pass in the indices to create a bezier curve of varying width, and then draw it.
There's also talk of interpolation and using a Loop-Blinn technique that seem to solve the specific problems of their respective questions. I believe that the solutions, however, might be too complex for what I'm going after. I'm also not interested bringing textures into the mix. I prefer that the triangles are just drawn using the colors I'll calculate later on in my shaders.
So, before I go into more reading on Trilinear Interpolation, Catmull-Rom splines, the Loop-Blinn paper, or explore sampling further, I'd like to make sure what direction is most likely to be the best bet. I think I can say the problem in its most basic form is to take a point in 3D space and find two parallel points along side it that take into account the direction the next point will be plotted.
Thank you for your time and if I can provide anything further, let me know and I'll do my best to add it.
This answer does not (as far as I see) favor one of the methods you mentioned in your question, but is what I would do in this situation.
I would calculate the normalized normal (or binormal) of the curve. Let's say I take the normalized normal and have it as a function of t (N(t)). With this I would write a helper function to calculate the offset point P:
P(t, o) = B(t) + o * N(t)
Where o means the signed offset of the curve in normal direction.
Given this function one would simply calculate the points to the left and right of the curve by:
Points = [P(t, -w), P(t, w), P(t + s, -w), P(t + s, w)]
Where w is the width of the curve you want to achieve.
Then connect these points via two triangles.
For use in a triangle strip this would mean the indices:
0 1 2 3
Edit
To do some work with the curve one would generally calculate the Frenet frame.
This is a set of 3 vectors (Tangent, Normal, Binormal) that gives the orientation in a curve at a given parameter value (t).
The Frenet frame is given by:
unit tangent = B'(t) / || B'(t) ||
unit binormal = (B'(t) x B''(t)) / || B'(t) x B''(t) ||
unit normal = unit binormal x unit tangent
In this example x denotes the cross product of two vectors and || v || means the length (or norm) of the enclosed vector v.
As you can see you need the first (B'(t)) and the second (B''(t)) derivative of the curve.

Resources