How do I translate barcode location to millimeters on page? - ironpdf

IronBarCode recently added coordinates (X1, X2, Y1, Y2) to their BarcodeResult class.
Unfortunately there is no documentation on how to translate these coordinates to sth usefull like "millimeters from left page border".
Do you have any ideas on how to do that?

Related

Project Tango -Start of Service Coordinate System, C API

I am working with the Motion Tracking app, trying to record the pose data on C API. The pose data is recorded with respect to the Start_Of_Service coordinate system. I am having trouble understanding this coordinate system.
Is the Z+ always aligned with gravity?
The back of the device is used as the Y axis?
The documentation says that the X-Y plane is perpendicular to Z and level with the ground. If Z+ is aligned with gravity and the Tango tablet is at an angle with gravity, how are the X and Y aligned?
Is the Z+ always aligned with gravity?
Per the docs:
Project Tango uses a right-handed, local-level frame for the START_OF_SERVICE and AREA_DESCRIPTION coordinate frames. This convention sets the Z-axis aligned with gravity, with Z+ pointed upwards, and the X-Y plane is perpendicular to gravity and locally level with the ground plane.
So yes. For START_OF_SERVICE and AREA_DESCRIPTION base frames.
The back of the device is used as the Y axis?
Per the docs:
Project Tango uses the direction the back of the device is pointed when the service started as the Y axis
Perpendicular to the device with y+ pointing out the back.
The documentation says that the X-Y plane is perpendicular to Z and level with the ground. If Z+ is aligned with gravity and the Tango tablet is at an angle with gravity, how are the X and Y aligned?
Imagine you are holding the device in the image at the START_OF_SERVICE Frame. Notice how the device is square with the room.
Now tilt the tablet forward or back about the x axis. The device moves, but all the axes stay the same.
Now rotate the device right or left about the y axis. All the axes stay the same.
So if your device is tilted, first rotate the device about the y axis, then about the x axis until the tablet screen aligns with the z axis...at which point it is easier to visualize where your axes are located.

OpenGL Rotate an Object around It's Local Axes

Imagine a 3D rectangle at origin. It is first rotated along Y-axis. So good so far. Now, it is rotated around X-axis. However, OpenGL (API: glrotatef) interprets the X-axis to be the global X-axis. How can I ensure that the "axes move with the object"?
This is very much like an airplane. For example, if yaw (Y rotation) is applied first, and then pitch (X-rotation), a correct pitch would be X-rotation along the plane's local axes.
EDIT: I have seen this called gimbal lock problem, but I don't think it is though.
You cannot consistently describe an aeroplane's orientation as one x rotation and one y rotation. Not even if you also store and one z rotation. That's exactly the gimbal lock problem.
The crux of it is that you have to apply the rotations in some order. Say it's x then y then z for the sake of argument. Then what happens if the x rotation is by 90 degrees? That folds the y axis onto where the z axis was. Then say the y rotation is also by 90 degrees. That's now bent the z axis onto where the x axis was. So now what effect does any z rotation have?
That's just an easy to grasp example. It's not a special case. You can't wave your hands out of it by saying "oh, I'll detect when to do z rotations first" or "I'll do 90 degree rotations with a special pathway" or any other little hack. Trying to store and update orientations as three independent scalars doesn't work.
In classic OpenGL, a call to glRotatef means "... and then rotate the current matrix like this". It's not relative to world coordinates or to model coordinates or to any other space that you're thinking in.

List of Control Points of Easing Functions

I'm looking for a list or a method to get the x1, x2, y1, y2 (KeySpline equivalent) values of the current Easing Functions (for ex: CircleEase with mode EaseInOut).
How I can get them?
Try the website easings.net , you could click on any easing graph and you will find the control points.

SnapsToDevicePixels issue

In my WPF app, I have created few Line elements and added inside a StackPanel. The thickness for all lines is set to 0.5. But when I render it, sometimes few lines are appearing blur. I tried setting SnapsToDevicePixels in the StackPanel but this makes the lines completely invisible. Now if I increase the line thickness to 1 or greater than 1 then SnapsToDevicePixels is working properly.
I am creating Line as shown below:
private void CreateLine(Double y1, Double y2, Double x1, Double x2, Double width, Double height)
{
Line line = new Line() { Y1 = y1, Y2 = y2, X1 = x1, X2 = x2, Width = width, Height = height };
}
Here, if LineThickness is set to 0.5, x1 and x2 values will be 0.25 (LineThickenss / 2) and width is 0.5 (LineThickness).
Is there any minimum pixel value required to be set in order to make the SnapsToDevicePixels work in WPF?
I solved many of my SnapToDevicePixels issues by using UseLayoutRounding instead:
In your case:
<StackPanel UseLayoutRounding="True">
...
</StackPanel>
I don't know if this will solve your issue, but from my experience, it's worth a try!
No, there isn't a minimum per se. The blurriness you are experiencing is due to how WPf handles drawing in general. According to my experience you can't really do anything about it. Snapping to device pixels may give some reprieve, but can still be unpredictable.
Also there is a difference between a pixel and a WPF unit that makes things more complicated, though many techniques exist to translate between them.
A common approach to translating the pixel to WPF unit is:
Matrix m = PresentationSource.FromVisual(this).CompositionTarget.TransformToDevice;
double dpiFactor = 1/m.M11;
double lineThickness = dpiFactor * 1; // Repace '1' with desired pixel size.
Here is a useful article on the topic:
http://www.wpftutorial.net/DrawOnPhysicalDevicePixels.html
It is not recommended to set fractional positions.
What means the half of WPF point?
WPF will interpret 1 point as 1/96 inch. It differs in pixels for distinct monitors (96 DPI, 300 DPI).
WPF considers 1 point as 1 pixel in the usual monitors with 96 DPI. And
UIElement.SnapsToDevicePixels works great. It tries to snap 0.5 pixel to the monitor grid. There are two results: enlarged version two one pixel or shortened version to 0 pixel (disappears).
If for some reason there is a need for exact 1 pixel (not 1 point) positioning then use GuidelineSet.
With .NET 4 or higher it is better to use Layout Rounding. It calculates pixel offsets at the UI position measuring level. While SnapsToDevicePixels works at the render level. The minus for Layout Rounding is that it is bad for dynamic moving.

Finding center of 2D triangle?

I've been given a struct for a 2D triangle with x and y coordinates, a rotation variable, and so on. From the point created by those x and y coordinates, I am supposed to draw a triangle around the point and rotate it appropriately using the rotation variable.
I'm familiar with drawing triangles in OpenGl with GL_TRIANGLES. My problem is somehow extracting the middle of a triangle and drawing the vertices around it.
edit: Yes, what I am looking for is the centroid.
There are different "types" of centers of a triangle. Details on: The Centers of a Triangle. A quick method for finding a center of a triangle is to average all your point's coordinates. For example:
GLfloat centerX = (tri[0].x + tri[1].x + tri[2].x) / 3;
GLfloat centerY = (tri[0].y + tri[1].y + tri[2].y) / 3;
When you find the center, you will need to rotate your triangle about the center. To do this, translate so that the center is now at (0, 0). Perform your rotation. Now reverse the translation you performed earlier.
I guess you mean the centroid of the triangle!?
This can be easily computed by 1/3(A + B + C) where A, B and C are the respective points of the triangle.
If you have your points, you can simply multiply them by your rotation matrix as usual. Hope i got you right.
There are several points in a triangle that can be considered to be its center (orthocenter, centroid, etc.). This section of the Wikipedia article on triangles has more information. Just look at the pictures to get a quick overview.
By "middle" do you mean "centroid", a.k.a. the center of gravity if it were a 3D object of constant thickness and density?
If so, then pick two points, and find the midpoint between them. Then take this midpoint and the third point, and find the point 1/3 of the way between them (closer to the midpoint). That's your centroid. I'm not doing the math for you.

Resources