Coreplot Intersection of X and Y axis - core-plot

Using the Mac OS framework I have the x and y axis interesecting at zero ( X interesects Y axis at Y = 0 and vice versa ) however the Y axis is at the far left of the screen where it is not visible .
Is it possible to specify a fixed margin for Y axis from the left of the plot area irrespective of the X Range ( and still maintain both the axes interesecting at 0 respectively) ?
One way i thought of doing this ( forcing a margin for Y axis ) was via specifying a negative value for the low X however this does not scale well when doing wide ranges of X ( 100's vs 1000's) . I need an easier way to predictably make X intersect Y at a fixed pixel offset in the chart to render it consistently .
I've tried using the y.orthogonalCoordinateDecimal = 0 . it does what it is meant to do ( make y intersect X at 0 ) however the actual intersection point in the graph is not where I desire . I want to be able to control the location of that intersection say 100 pixels for X and 80 pixels for y .

Use the axisConstraints to hold the y-axis at the left side of the graph:
y.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
If you always give the xRange of the plot space a location of zero, this will give the appearance you want.

Related

my vertical x axis labels run into my plotted data. Is there a way to compress the graph so I have a little extra room at the bottom

I am plotting my x axis labels vertically, and using the following line to provide a little space under the axis
axisSet.xAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:40.0];
But now the vertical length of the label bumps into the first value on the y axis. Is there a way to compress the graph a little so the first value on the y axis begins a little higher? Thanks.
Adjust the axis' labelAlignment and/or labelOffset to reposition the labels.

Find the smallest x for given y for a rotated UIView

I transformed some UIView with a CGAffineTransform. Now I want to know if it possible to get the smallest x point of the UIView when proving some y value in the UIView.
For example in the picture below, I want to know the smallest x value for a y value which is 0.75 the view's height.
someView.frame.origin.x provides only the x value for the top-left position, but I need something to change that position to get the smallest x value of a given y value.
I assume you can calculate the minimum X and its corresponding Y on the rotated square.. Then calculate the X2, Y2 as shown in the picture below once you know the angle the square has rotated and the length of its sides (then its Pythagorean theorem)..
I used let rotatedRect = CGRectApplyAffineTransform(rotationTransformation, square.frame) to get the rotated rectangle's coordinates. Then I compared all 4 points to find the one with the smallest X value and the equation of the two lines of the square that go through that point (one has positive slope, the other has negative).
Once you have X1, Y1 and X2, Y2, X3, Y3 as shown below, you can calculate the interception of two lines by substitution or elimination as shown below..
To make it simple, I assumed the slope of the line passing through the square was 0 (horizontal-line).
To figure out which is the correct minimum X value, you compare if the X >= X1. If it is, that is the minimum that satisfies your requirements. See below for example..
as the UIView is always a rectangle, I suppose you want to track the minimum x for a given y just for rectangles.
SOLUTION
you can track the position of the 4 vertexes of the UIView always you rotate it. This tracking can be done by simply multiplying the points for a 2x2 rotation matrix.
| cosθ -senθ | | x | = | x * cosθ - y * senθ |
| senθ cosθ | | y | | x * senθ + y * cosθ |
Then, you can get the vertex with minimum x (lets call it V1).
then you need to get other 2 vertexes with the minimum x (called V2 and V3).
if V1.y > (given y)
write linear equation from V1 to vertex with minimum y between V2 and V3
else
write linear equation from V1 to vertex with maximum y between V2 and V3
in the end you will have f(x) = ax + b
replace the given y for f(x) and you get x = (y - b)/a
hope that helps :)

iOS Core Plot "Function transformation" - Y axis only origin

I cannot find how to do this for a while now, my graph is drawn ok every time but I want to move up my graph, like when you have f(x) + n. So, what I want to do actually is change Y origin, so I can draw my (x,0) points. I do not want to draw my points on X axis, I do not see the line that good. I want that my zero Y point actually starts at point three, but not to transform the graph at the same time. Here is picture of what I want to do (see the green line and Y point):
The plot space yRange controls the range of data visible. The image in the question looks like it has a location of negative one (-1) and length of 18. You can use the axisConstraints to keep the x-axis along the bottom of the plot area. If you don't want to use constraints, set the orthogonalPosition to the location of the yRange.

Is it possible to highlight x and y axes on Highcharts

I have created a scatter chart with Highcharts, both x and y axes range is from -20 to 20. It is shown as a grid, I set "gridLineWidth: 1" both for x and y, so all the lines have the same width.
Is it possible to give a different width only to x and y axes which cross the origin?
I've solved using plotLines to both axes.

trying to understand the Affine Transform

I am playing with the affine transform in OpenCV and I am having trouble getting an intuitive understanding of it workings, and more specifically, just how do I specify the parameters of the map matrix so I can get a specific desired result.
To setup the question, the procedure I am using is 1st to define a warp matrix, then do the transform.
In OpenCV the 2 routines are (I am using an example in the excellent book OpenCV by Bradski & Kaehler):
cvGetAffineTransorm(srcTri, dstTri, warp_matrix);
cvWarpAffine(src, dst, warp_mat);
To define the warp matrix, srcTri and dstTri are defined as:
CvPoint2D32f srcTri[3], dstTri[3];
srcTri[3] is populated as follows:
srcTri[0].x = 0;
srcTri[0].y = 0;
srcTri[1].x = src->width - 1;
srcTri[1].y = 0;
srcTri[2].x = 0;
srcTri[2].y = src->height -1;
This is essentially the top left point, top right point, and bottom left point of the image for starting point of the matrix. This part makes sense to me.
But the values for dstTri[3] just are confusing, at least, when I vary a single point, I do not get the result I expect.
For example, if I then use the following for the dstTri[3]:
dstTri[0].x = 0;
dstTri[0].y = 0;
dstTri[1].x = src->width - 1;
dstTri[1].y = 0;
dstTri[2].x = 0;
dstTri[2].y = 100;
It seems that the only difference between the src and the dst point is that the bottom left point is moved to the right by 100 pixels. Intuitively, I feel that the bottom part of the image should be shifted to the right by 100 pixels, but this is not so.
Also, if I use the exact same values for dstTri[3] that I use for srcTri[3], I would think that the transform would produce the exact same image--but it does not.
Clearly, I do not understand what is going on here. So, what does the mapping from the srcTri[] to the dstTri[] represent?
Here is a mathematical explanation of an affine transform:
this is a matrix of size 3x3 that applies the following transformations on a 2D vector: Scale in X axis, scale Y, rotation, skew, and translation on the X and Y axes.
These are 6 transformations and thus you have six elements in your 3x3 matrix. The bottom row is always [0 0 1].
Why? because the bottom row represents the perspective transformation in axis x and y, and affine transformation does not include perspective transform.
(If you want to apply perspective warping use homography: also 3x3 matrix )
What is the relation between 6 values you insert into affine matrix and the 6 transformations it does? Let us look at this 3x3 matrix like
e*Zx*cos(a), -q1*sin(a) , dx,
e*q2*sin(a), Z y*cos(a), dy,
0 , 0 , 1
The dx and
dy elements are translation in x and y axis (just move the picture left-right, up down).
Zx is the relative scale(zoom) you apply to the image in X axis.
Zy is the same as above for y axis
a is the angle of rotation of the image. This is tricky since when you want to rotate by 'a' you have to insert sin(), cos() in 4 different places in the matrix.
'q' is the skew parameter. It is rarely used. It will cause your image to skew on the side (q1 causes y axis affects x axis and q2 causes x axis affect y axis)
Bonus: 'e' parameter is actually not a transformation. It can have values 1,-1. If it is 1 then nothing happens, but if it is -1 than the image is flipped horizontally. You can use it also to flip the image vertically but, this type of transformation is rarely used.
Very important Note!!!!!
The above explanation is mathematical. It assumes you multiply the matrix by the column vector from the right. As far as I remember, Matlab uses reverse multiplication (row vector from the left) so you will need to transpose this matrix. I am pretty sure that OpenCV uses regular multiplication but you need to check it.
Just enter only translation matrix (x shifted by 10 pixels, y by 1).
1,0,10
0,1,1
0,0,1
If you see a normal shift than everything is OK, but If shit appears than transpose the matrix to:
1,0,0
0,1,0
10,1,1

Resources