I am using the Octave plot function to plat a 2D graph. I want to scale the x axis by 2x (no change to y axis). i.e. the distance between each unit in x axis is doubled.
How do I do that in Octave?
You have to use the parameter "dataaspectratio" of the function "set" to modify the aspect ratio of the plot (as the self explaining parameter name indicates). dataaspectratio accepts a 3-element vector, with the scales for X,Y and Z, so if you want X to be double as the Y axis scale you should use:
set(gca,'dataaspectratio',[2 1 1])
Related
When transforming a quaternion to Euler Angles, usually there has to be a order in which the axes are rotated, like in this visualization.
How does it work for libgdx?
The Quaternion class has the functions
getRoll():
Math.asin(MathUtils.clamp(2f * (w*x - z * y), -1f, 1f)) :
(float)pole * MathUtils.PI * 0.5f;`
getPitch():
Math.asin(MathUtils.clamp(2f * (w*x - z * y), -1f, 1f)) :
(float)pole * MathUtils.PI * 0.5f;`
getYaw():
`
MathUtils.atan2(2f * (y * w + x * z), 1f - 2f * (y * y + x * x)) : 0f;`
Where is the order of the resulting angles set, which axes is rotated first,second,third ?
How are these functions related to a quaternion rotation matrix like:
Why is it that often this Rotationmatrix is given as Inverse /Transposed (equal because of orthogonality) ?
Rotation order
There are 12 possible orders of rotations possible for using an angle triplet for orientation.
Six of them are called Proper Euler angles, and rest six are called Tait–Bryan angles.
Read more here
Libgdx uses the following order.
Rotate by yaw about Y
Elevate by pitch towards Y
Rotate by roll about obtained direction
Rotation Matrix
Rotation matrices, Quaternions, Euler angles and Axis-Angle representation are different ways to encode rotation/orientation.
They often trade off between storage space and computation cost.
They can be freely converted into each other by means of well defined equations, one of which you mentioned. So these conversion expressions are related to each other.
Edit
Thanks for pointing out the mistake. It is indeed about Y axis not Z.
I have verified it from the source code.
Libgdx uses coordinate system of bullet physics engine. In that system, XZ plane is considered horizontal and Y is considered upwards (not Z). This was the root of my mistake.
I am trying to create a graph calculator and making it display the graph correctly on a "canvas". When I load the HTML file and write x e.g it starts from the upper left corner and goes down to the lower right corner. So the problem is that it displays the graph upside down and it does not include negative values.
I know that the canvas starts from (0,0) in pixel value in the upper left corner and ends at (300,300) in the lower right corner. I want it to display something like the green canvas from this link: http://www.cse.chalmers.se/edu/course/TDA555/lab4.html
points :: Expr -> Double -> (Int,Int) -> [Point]
points exp scale (x, y) = [(x, realToPix (eval exp (pixToReal x))) | x<-[0..(fromIntegral canWidth)] ]
where
pixToReal :: Double -> Double --converts a pixel x-coordinate to a real x-coordinate
pixToReal x = x * 0.02
realToPix :: Double -> Double --converts a real y-coordinate to a pixel y-coordinate
realToPix y = y / 0.02
You're probably used to working with 2D coordinate systems where positive y is up, but as you noted in HTML canvas positive y goes down. To simulate the coordinate system you want, you need to flip all the y-values over the line y=0 (aka the x-axis).
Here are a few y-values and their corresponding corrections you can use as tests. Note that I'm assuming y has already been scaled properly; it looks like you've already got that part.
150 -> 0
0 -> 150
-150 -> 300
The pattern is y_new = -(y_old - 150) where 150 is canvas_height/2. Therefore, after scaling you need to apply this formula to all your y values.
To shift the y-axis to the center you need to do the same sort of thing to derive the appropriate linear transformation.
In this ActionScript reference on the atan2 function, it reads:
Computes and returns the angle of the point y/x in radians, when
measured counterclockwise from a circle's x axis (where 0,0 represents
the center of the circle). The return value is between positive pi and
negative pi. Note that the first parameter to atan2 is always the y
coordinate.
For example
Math.atan2(0.7071, -0.7071)
(note that the first parameter is the Y coordinate) returns 2.356, which is positive Pi*3/4.
But in Flash graphics the Y axis goes down, not up. Shouldn't it be "clockwise" instead?
This is the general description of what the atan2 function does in all programming languages.
With that said, you have to indeed put atan(-dy,dx) to get the counter-clock wise angle in screen coordinates, or atan2(dx,dy) to get the zero angle pointing upwards.
I have to plot a polyline in HTML5 canvas where y axis points are both positive and negative.
such as y=[5,10,50,-150,80,-90]. The x-axis is spaced at 1. x=[1,2,3,4,5,6].
I am trying to use translate() and scale() to plot this, but so far not successful.
If someone could point how both positive and negative points be plotted in canvas it will be great.
Suppose your canvas is 1000 by 1000 and you want to plot points that are 0 to 7 in the x and -200 to 100 in the y. Then you need to do two things:
1) Recenter so that the origin is at (0, 333.3) in pixel coordinates. You would do this with translate(0, 333.3).
2) Scale so that an x of 7 appears at pixel position 1000 and y of 100 appears at pixel position -333.3 (now the top of the window). You would do this with scale(1000 / 7, -333.3 / 100).
More generally, for canvas size (w, h) and axis ranges xmin...xmax and ymin...ymax, you would do:
ctx.translate(w * xmax / (xmax - xmin), h * ymax / (ymax - ymin));
ctx.scale(w / (xmax - xmin), -h / (ymax - ymin));
I have data like this
x-axis data values
-20.49, -12.23, -9.99, -1.00 0 , 1.12, 2.23, 3.45, 4.56, 8.99, 20.99, 30.23
y-axis data values
10,20,20,40,50,60........
I would like to transform above given data into xy coordinate system.
Please have look at the image.
For eg:
along x-axis (min, max ) data value (-20.49, 30.23),
along y-axis (min, max ) data value (10,60)
now if I want plot data(-20.49, 10) in image,
the X coordinate is going to be =200,
and Y-coordinate going to be = 220.
Like this I want plot all data fits within the range of rectangle.
Hope this gives all details
Thanks
This is more of the math question, not related to any programming language. And speaking about Actionscript 3, it has Y axis going from top to bottom, not from bottom to top. Anyway: If you have two points on an axis that you want to map to screen coordinates of your choice, record xmin as lesser native value, xmax as greater native value, and coordinates as xleft and xright. Then, when you need to receive a screen coordinate for your given x, you calculate the xcoord value as:
xcoord = xleft + (x - xmin)*(xright - xleft)/(xmax - xmin);
Similar approach will net you correct values for the Y axis.