Is there a way to set the (0,0) point in the center of the Canvas in SkiaSharp? - xamarin

I'm using SkiaSharp in Xamarin.Forms (after an unsuccessful attempt with Path shapes) and I have created a Cartesian coordinate system drawn on the Canvas.
Is it possible to move the (0, 0) point in order for it to coincide with the origin point of my Cartesian plain?
In other words, I would like e.g. a circle drawn with canvas.DrawCircle(0, 0, radius, paint); to be centered on the Canvas. That would simplify things when giving coordinates in order to draw other stuff.

Related

Why do I have to normalize coordinates?

I see that everybody normalizes his coordinates to be in range of [-1;1]. Why is this done? Is this required? Is this only for ThreeJS , or is it a common thing for every 3D framework?
Three.js is based on WebGL and WebGL is based on OpenGL ES (Embedded System)
In WebGL / OpenGL ES there is a viewport:
2.3 The WebGL Viewport
OpenGL manages a rectangular viewport as part of its state which defines the placement of the rendering results in the drawing buffer. Upon creation of the WebGL context, the viewport is initialized to a rectangle with origin at (0, 0) and width and height equal to (canvas.width, canvas.height).
5.13.4 Viewing and clipping
The viewport specifies the affine transformation of x and y from normalized device coordinates to window coordinates. The size of the drawing buffer is determined by the HTMLCanvasElement. The scissor box defines a rectangle which constrains drawing. When the scissor test is enabled only pixels that lie within the scissor box can be modified by drawing commands. When enabled drawing can only occur inside the intersection of the viewport, canvas area and the scissor box. When the scissor test is not enabled drawing can only occur inside the intersection of the viewport and canvas area.
This means gl.viewport defines the transformation from normalized device coordinates to the viewport rectangle.
Because of that everything which is drawn and should be shown on the viewport, has to be in the normalized device space, which is in the range from (-1,-1,-1) to (1, 1, 1).
Transformation of the geometry to normalized device coordinates:
The geometry is transformed by its model matrix, to world coordinates.
To transform from wolrd coordinates to normaliced device coordinates, Three.js provides the THREE.OrthographicCamera or the THREE.PerspectiveCamera. The camera defines a view matrix and a projection matrix.
The view matrix describes the direction and position from which the scene is looked at. The view matrix transforms from the wolrd space to the view (eye) space. In general world coordinates and view coordinates are Cartesian coordinates.
The projection matrix describes the mapping from 3D points of a scene, to 2D points of the viewport. The projection matrix transforms from view space to the clip space. Clip space coordinates are Homogeneous coordinates. The coordinates in the clip space are transformed to the normalized device coordinates (NDC) in the range (-1, -1, -1) to (1, 1, 1) by dividing with the w component of the clip coordinates.

Photoshop smart object: get rotation angle via Applescript?

I have tried and failed to find an Applescript code that returns a smart object's current rotation angle in Photoshop. Anyone have an idea of where that property is listed? I'm beginning to think this feature isn't currently supported by Applescript.
In Photoshop, objects like a selection has no angle value, because it means nothing: if your selection is made by multiple segments making a complexe shape, there is no mathematical way you can define angle for that shape !
However, you can work with boundary rectangle (which includes that shape). You can rotate this complete boundary (i.e. the selection) and then you will get a new boundary (new rectangle where new rotated shape fits in).
A boundary rectangle is made of a list of for values :
top left corner horizontal position (X1)
top left corner vertical position (Y1)
bottom right corner horizontal position (X2)
bottom right corner vertical position (Y2)
Positions are real numbers, starting with border of canvas (not border of layer ! so you may have negative values). The units depends of the unit of measure of the document.
Once that's clear (I hope !) if you use mathematical calculation between initial boundary and new boundary, you can calculate the rotation angle:
(Pythagore triangle)
If you assume that initial rectangle borders were vertical and horizontal :
cosinus (Teta) = (X2-X1) / (X'2 - X'1)
Teta = angle you are looking for
X1, X2 are the positions of the boundary corners before rotation and X'1, X'2 are position of same corners after rotation.
Please note that this method is OK for selection (any shape), or layers.
It should also be OK for the full canvas, but I never test it for canvas.

Displaying arc within a rectangle

There is a problem:
Have a rectangle, the coordinates of the lower left corner - (0, 0), upper right (width of the rectangle, the height of the rectangle). Inside this rectangle is the point having certain coordinates. I need to draw around this point a segment of a circle with a certain (const) arc length. Calculate the internal radius and the angle of the segment of a circle.
illustration:
Like this. As can be seen from the figure, if the segment to be placed in the side of the screen (eg bottom left), it is necessary to find such a range that it satisfies our long arc.
Prompt, in what side to search?
Thank you in advance.

Get the coordinates of the corners of a rectangle superimposed on a map

I'm developing an app that shows a mapview.
Superimposed at this I draw a rectangle that always has the center in the screen center, therefore the center of the map.
I can move a corner of the rectangle to resize it to select an area on the map.
I have only the coordinates (lat/lon) of the center of the rectangle (and of the map), the altitude and the size of the rectangle (pixel or cm).
How can I get the coordinates of the rectangle corners??
Should I calculate the scale between the size of the rectangle and the altitude of the map? and then?
please explain me this problem :)
thanks in advance
I found the solution.
I've developed the app for BlackBerry 10 and in MapView class there are some methods that are very useful.
Getting the coordinates of the corner of the rectangle drew on the mapview (for example to choose an area on the map)
using
bb::platform::geo::Point windowToWorld (const QPoint &windowCoordinates)
call windowToWorld passing the coordinates of the pixel of the corners, relatively to the axis origin. The method returns the coordinates (lat/lon) of the point on the screen (x,y).
WARNING: The origin of the window's coordinates are the upper left corner of the MapView window (not the screen), with positive values going right (x-axis) and down (y-axis).
If you want to do the inverse use the worldToWindow method that converts world coordinates (latitude/longitude) into window coordinates (pixels).
eg: draw a geo point on the mapview

How to find orientation of rubik cube?

I'm trying to make a rubik cube game in webgl using three.js (you can try it here).
And I have problems to detect on witch axis I have to rotate my cube according the rotation of the cube. For instance, if the cube is in original position/rotation, if I want to rotate the left layer from down to up, I must make a rotation on the Y axis. But I rotate my cube 90 degrees on Y, I will have to rotate It on the Z axis to rotate my left layer from down to up.
I'm trying to find a way to get the correct rotation axis according the orientation of the cube.
For the moment I check witch vector of the axis of the rotation matrix of the cube is most parallel with the vector(0,1,0) if I want to move a front layer from down to up. But it do not works in edge cases like this for instance :
I guess there is some simple way to do that, but I'm not good enough in matrix and mathematical stuff :)
An AxisHelper can show the aixs of the scene which you could determine the orientation with.
var axishelper = new THREE.AxisHelper(40);
axishelper.position.y = 300;
scene.add(axishelper);
You could also log your cube and check the position and rotation properties with Chrome Developer Tools or Firebug.
You can store the orientation of each cube in its own 4x4 matrix (i.e. a "model" matrix) that tells you how to get from the cube's local coordinates to the world's coordinates. Now, since you want to rotate the cube around to an axis (i.e. vector) in world coordinates, you need to translate the axis into cube coordinates. This is exactly what the inverse of the model matrix yields.

Resources