Flipping Views in SwiftUI - swiftui

In my SwiftUI app, I have an Image:
I added this image using:
Image("shoe_test")
.resizable()
.frame(width: 275, height: 275)
.rotationEffect(Angle(degrees: 30))
However, I would like to flip this image in the opposite direction, like:
For this, I haven't tried anything, but I had no luck with rotationEffect, and I can't get my head over this, Any help is greatly appreciated,

You could use
.rotation3DEffect(.degrees(180), axis: (x: 0, y: 1, z: 0))
documentation
With the rotation3DEffect you can rotate your image in all 3 Dimensions.
rotating along the x axis will flip the image top/bottom
rotating along the y axis will mirror it right/left
rotating along the z axis will flip and mirror it.

It can be done with scale
.scaleEffect(x: -1, y: 1) // flip horizontally
.scaleEffect(x: 1, y: -1) // flip vertically

Related

Any way to make the y-axis border longer in chart.js?

Any way to make the y-axis border longer on either side in chart.js?
HAVE
WANT
While looking how to add padding between the tick marks and x-axis, I found a solution which allows me to do just that plus the above.
Which is by setting the y offset to true and hiding the x border:
Copied from here:
x: {
grid: {
drawBorder: false, // hide the x axis
},
},
y: {
offset: true, // create a sensation of space with the x axis hidden
},
In my case, it's enough.

What value should Z actually be for perspective divide?

So I'm trying to understand the fundamentals of perspective projection for 3D graphics and I'm getting stuck. I'm trying to avoid matrices at the moment to try and make things easier for understanding. This is what I've come up with so far:
First I imagine I have a point coming in with screen (pixel) coordinates of x: 200, y: 600, z: 400. The z amount in this context represents the distance, in pixels, from the projection plane or monitor (this is just how I'm thinking of it). I also have a camera that I'm saying is 800 pixels from the projection plane/monitor (on the back side of the projection plane/monitor), so that acts as the focal length of the camera.
From my understanding, first I find the total z distance of the point 200, 600 by adding its z to the camera's focal length (400 + 800), which gives me a total z distance of 1200. Then, if I wanted to find the projected point of these coordinates I just need to multiply each coordinate (x & y) by (focal_length/z_distance) or 800/1200 which gives me the projected coordinates x: 133, y: 400.
Now, from what I understand, openGL expects me to send my point down in clips space (-1 to 1) so I shouldn't send my pixel values down as 200, 600. I would have to normalize my x and y coordinates to this -1 to 1 space first. So I normalize my x & y values like so:
xNorm = (x / (width/2)) - 1;
yNorm = (y / (height/2)) - 1;
This gives me normalized values of x: -.6875, y: -.0625. What I'm unsure of is what my Z would need to be if openGL is going to eventually divide these normalized values by it. I know aspect ratio probably needs to be entered into the equation but not sure how.

Qt 5.5 draw filled pie

The image below shows the grey pie, I would like to draw this using Qt 5.5
X increases left to right
Y increases top to bottom
I have a start angle and an end angle which represents to the top and bottom of the arc, I am calculating the arc angle using:
double dblArcAngle = fmod(mcfltElevMaxLimit - mcfltElevMinLimit + 180.0, 360.0) - 180.0;
Where:
mcfltElevMaxLimit is 60 and mcfltElevMinLimit is -10
The call to drawPie looks like this:
objOffscrPainter.drawPie(QRect(rctGeom.left() + mcintElevLeftMargin
,rctGeom.top() + mcintElevBottomMargin
,rctGeom.width() - mcintElevLeftMargin
,rctGeom.height() - mcintElevBottomMargin)
,mcfltElevMaxLimit * 16, dblArcAngle * 16);
What I get is a very small polyline about midway up where the pie should be.
(edit), just read in the documentation that both startAngle and spanAngle parameters 2 and 3 should be multiplied by 16, which does produce a pie, not in the correct orientation and not filled to the center but its progress.
(edit 2), more progress, the image below now shows the results I'm getting, the rectangle I'm passing is the outer rectangle and includes the axis, yet for some reason the pie is offset???
What I want to accomplish is the pie tucked into the bottom left aligned with the white axis and filling the image.
It looks like the passed rectangle is used to determine the center point for the pie. If this is correct then the center of the rectangle must be adjusted to be the origin (bottom left) and the size also adjusted to fill the display.
The rectangle in a first parameter of QPainter::drawPie is a bounding box of a circle which contains your arc. So, to draw what you need try something like this:
objOffscrPainter.drawPie(QRect(center.x() - r, center.y() - r, 2 * r, 2 * r)
,16*mcfltElevMaxLimit, 16*dblArcAngle);
(where center is a center of your arc)
It seems that in your case center is a QPoint(0, 0), so you can use this code:
objOffscrPainter.drawPie(-r, -r, 2*r, 2*r, 16*mcfltElevMaxLimit, 16*dblArcAngle);
(we can call it without QRect too, see the documentation)

Translating x,y while scaling

I'm trying to graph x,y coordinates where the window size is 600px by 600px. (0,0) would be in the top left.
(300,300) middle of the window.
(600,600) would be in the bottom right.
I am trying to translate latitude/longitude in radians to pixels and then plotting them.
I'm calculating 1px = ? lat by
`fabs(lborder+rborder)/600`
I calculated lon by taking the top and bottom borders.
Then when I want to find a specific position for a specific lat or lon:
lat/(previous # calculated above)
Problem is my window goes from 0,0 to 600,600 as explained above and I can get negative points and I'm not sure how to move them and I don't know how to center them around 300,300 when the bounds change.
At the moment, as long as I make the center (0,0) in terms of (x,y), not pixels, points get plotted where they're supposed to go.
For example, if x is -1 to 1 and y is -3 to 3, (300px,300px) would be (0,0).
If I change the bounds to say x -.5 to 1 and y -3 to .5, (300px,300px) would be (.25, 1.25). However, the calculations above with these numbers.
1.5/600 = .0025 ----> 1px = .0025lat.
3.5/600 = .0058 ----> 1px = .0058lon.
Then taking the midpoint (.25,1.25):
.25/.0025 = 100px
1.25/.0058 = 215px
which is clearly not 300px,300px despite being the center of the graph.
Any ideas would be extremely helpful.
If you would like to adjust the coordinates to the center, then maybe somthing like this?
Coord coordsFromCenter(Coord old_coord, float height, float width)
{
Coord new_center;
float new_x_center = width/2.0;
float new_y_center = height/2.0;
new_center.set_x(old_coord.get_x() - new_x_center);
new_center.set_y(old_coord.get_y() - new_y_center);
return new_center;
}

Horizontal line in Google scatter chart

I'm using a scatter chart to display data with the following range: x = [-1..1] y = [-1..1]. Is it possible to draw a horizontal line on e.g. y = 0.5?
I'm using the JavaScript charts (i.e. not the image charts).
We had the same problem at work. Unfortunately, for the moment Google Charts does not provide an easy way to display a line in the scatter chart, like in the bar chart.
Finally we found a "small trick" that works perfectly for us, as you can see here:
http://csgid.org/csgid/statistics/structures
The trick consist in creating a "Line chart" but setting the linewidth property to 0 and pointsize to 5 in the series of the points, and linewidth 1 and pointsize 0 in the serie of the line.
It looks like:
interpolateNulls: true,
series: {
0: { lineWidth: 0, pointSize: 5 },
1: { lineWidth: 0, pointSize: 5 },
2: { lineWidth: 0, pointSize: 5 },
3: { lineWidth: 0, pointSize: 5 },
4: { lineWidth: 1, pointSize: 0 }
}
Why did I set interpolateNulls to true? Because then, I had to change the way I was setting the data in the array before convert it to JSON and pass it to Google Charts. In every row I had to set the values of every serie in the X axis for each value of the Y axis. So I had to set to null the X value when a serie didn't have a Y value for that X value (I mean, when a serie didn't have any point for that X value). So, the same for the serie of the line.
This would be one point of the first serie (in JSON):
[2.6,0.184,null,null,null,null]
And this one "point" of the line serie (the last serie):
[4,null,null,null,null,0.254]
Maybe it is not the most efficient way, but it works :)
I hope I have explained it clear, let me know if you have more questions.