Curved Shape Background Header in Flutter - dart

I have a list view with "Hero" icons on the left. When I click a list item, it loads the next screen with the article text and the Hero image (which animates nicely/automatically to the correct spot on the 2nd screen).
I would have thought that was the "tough" part, but I'm now trying to get a curved shape as the top background of the 2nd screen. I would love to make it a drawn vector shape, as opposed to a bitmap and even have it drip/bounce onto the page, but at the moment...
I'm just trying to figure out how to:
draw a vector shape
have it as the background of a screen with other widgets on top (see purple curve on 2nd screen below)

I made a full sample for your curved shape in a gist here
I used CustomPainter to draw on a canvas then, with some geometric calculations, I achieved the curved shape.
Final result
How I draw it?
Before coding and on a Whiteboard I determined somethings:
My Canvas Area:
The canvas dimensions I need to draw that shape (which equals to Flutter widget's dimensions).
How and where my brush will move?
how means: what are the APIs I need to draw that shape on the canvas using the Path class.
e.g. lineTo() for a straight line, quadraticBezierTo() for a curve.
where means: Where are the points (coordinates) I need to draw the whole shape. (see yellow and green dots in the image above)
Points (coordinates) Calculations:
I used some geometric equations to calculate the coordinates. e.g. Point on a circle’s circumference
All of my calculations depend on the canvas size, that gives me a responsive shape.
Full sample here!

Related

Figure out if points lays in area

Given and image and 4 corner points of an area inside the image, I want to figure out if a point p (x,y) lays inside the given area. The area is not necessarily in form of a rectangle, as the area is the result of a perspective projection of some other image.
For example:
Here I want to figure out if the pink point actually lays within the shape inside the image. In this case it does.
I was thinking about drawing an contour with drawContours and then using pointPolygonTest but I was wondering if there is an easier and more tailored way of doing it.

Manim - semi-transparent sphere doesn't cover lines

I'm trying to animate a trajectory of a particle on a spherical surface in manim. I made the sphere semi-transparent so it's easy to say when the particle is on the front side and when it is on the back side of the sphere. However after I plot the trajectory, even the parts that are supposed to be behind the sphere are the same color as the ones in front of it.
As you can see this issue is not present in the coordinate axes. The parts of axes that are inside of the sphere have different color, because the semi-transparent surface is between them and camera.
I'm using the following code
S=Sphere(center=(0,0,0), radius=1.09,resolution=(15, 15)).set_opacity(0.4)
S.set_color(GRAY)
self.add(axes,S)
for i in range(100):
self.play(Create(Traj[i]))
Where Traj is an array consisting of line elements of the trajectory.
Even if I set the sphere opacity to 1, I can still see the whole trajectory, even if most of it should be behind the spehre. How to make the sphere cover the back part of the trajectory?

Edit/finetune shapes drawn by Opencv

My requirement is to draw a rectangle on an image using program and allow the user to fine tune the length/width position with the mouse. And, get back the modified details into the program. I am using OpenCV, Linux.
Currently I am using library function to draw the basic shape on the image
polylines(image, &p, &n, 1, true, Scalar(0,0,255), 2, LINE_AA);
I understand the shape drawn here is part of the image and not treated as a layer above the image. Harder way to achieve what I want is
Highlight the shape by placing small filled circles at the corners and filling the shape by translucent color, upon mouse click
track the mouse drag and move the corners accordingly to re-size the shape, if first clicked on the corner circles
if clicked within, move the shape itself
The program has to continuously check for mouse clicks, track their movement and keep drawing shapes at new position to give user the feedback.
Is there any single function to achieve the same or any easier method?
Thank you.

rotated crop in opencv

I am trying to crop a picture on right on along the contour. The object is detected using surf features and than i want to crop the image of extactly as detected.
When using crop some outside boundaries of other object is includes. I want to crop along the green line below. OpenCV has RotatedRect but i am unsure if its good for cropping.
Is there way to perfectly crop along the green line
I assume you get you get your example from http://docs.opencv.org/doc/tutorials/features2d/feature_homography/feature_homography.html, so what you can do is to find the minimum axis aligned bounding box around the green bounding box, crop it from the image, use the inverted homography (H.inv()) matrix to transform that sub image into a new image (call cv::warpPerspective), and then crop your green bounding box (it should be axis aligned in your new image).
You can get the equations of the lines from the end points for each. Use these equations to check whether any given pixel lies within the green box or not i.e. does it lie between the left and right lines and between the top and bottom lines. Run this over the entire image and reset anything that doesn't lie within the box to black.
Not sure about in-built functionality to do this, but this simple methodology is guaranteed to work. For higher accuracy, you may want to consider sub-pixel checks.

Calculating the cells contained inside a rectangle on an Isometric Grid

Consider that we are given an isometric grid (consider something like Diablo) of tiles. We have some measures for the grid, like grid height, grid width and tile height/width. Consider this image:
The center cell of the grid is 0,0 extending iso-north (+y), iso-south(-y), iso-east(+x), iso-west(-x).
Let's say we to draw a rectangle at an arbitrary location on the grid. We do NOT have the isometric positions for the rectangle, but rather have the normal draw coordinates for the grid where the top left hand corner is 0,0 and south is y+, right is x+.
If we had the top, left, height, width of the rectangle in question - how could we calculate an array of iso-cells that crossed by the bottom edge of the rectangle.
Any language you choose to demonstrate this will suffice.
In some papers and books about isometric programming (Isometric programming with Direct X7, yes its old but gives an overview about the problems and techniques) they use mousemaps.
Also there is the technique to render the area of the map covered by the rectangle into an image, each tile gets a unique color (and it is just the color rendered). Afterwards they check which colors are in the image and so extract the list of tiles.
Since you are using a classic isometric tile width half height there could be a mathematical solution too. Unfortunatly an suggested algorithm would depend heavily on your map layout.
The code for a Java based TileSystem can be found here

Resources