How to animate the bezier line? - animation

We have a compass in our app and for the needle we are using an image. Which appears very pixellated...
It is possible to use a bezier line for the needle instead of a image?
If so how can i get it to rotate - like a compass needle, and for that line to react and move dependant to location changes?Can anyone please assist us with this, thanks.

Usually you don't have to rotate bezier path itself. You can apply affine transform to context to achieve necessary rotation.

Related

How do I animate an SDF circle along a circular path using patches?

I have some SDF circles in spark ar studio that I need to animate in a circular path continuously. Is this possible? at the moment animating with patches I can only animate into a straight line using the x and y coords. How would I go about doing this?
Heres how it is currently set up.
You can achieve a circular path using sine and cosine, by animating the transition values from 0 to 2*Pi (6.283). Here is an example:
There are some nice visualizations that explain how sine and cosine work, for example: https://www.reddit.com/r/visualizedmath/comments/7runef/unit_circle_visualization_of_sine_and_cosine/

Add triangles along path with D3

I am trying to replicate the image below using OpenLayers and D3.js.
I have tried to add triangles along the path using getPointAtLength() and just adding them as SVG elements, but that does not take care of the orientation of the line. To get this working I would need to find the slope and rotate each triangle.
I have also taken a look at this StackOverflow answer:
How to place arrow head triangles on SVG lines?
This looks great but unfortunately it only works for polylines. However, since I am using D3.js together with OpenLayers it seems like I have to use paths and not polylines since I need the d3.geo.path function to transform all features on the map.
As for now it seems like I have the following options:
Add triangles along the path by calculating the slope at every point. Is there an easy way to calculate slope along a path?
Somehow combine D3.js og and OpenLayers and use polylines instead of paths. Is this possible?
Somehow convert my path to a polyline and draw that one instead of the path. Is there a function for doing this?
Are there other options that I can test out?
You could call getPointAtLength at two points separated by a delta. The slope of the two points would be the slope of the path if the delta is small enough.

How to rotate an image x degrees then move in that direction?

I'm a newbie to KineticJS and have been going through the tutorials. I want to take an image that has a 'front' and rotate it a random number of degrees and then have it move forward a number of pixels/inches in that new direction.
I was able to use this rotation tutorial to rotate my image.
I see how to use transitionTo to send an image to an x/y coordinate.
I'm having trouble tying the two together. I feel like I need randomly generate e a new x/y coordinate and then determine the degree difference between where my image is pointing and a line drawn from the center of the image to the new x/y point.
Does anyone have any tips for doing something like this? How would one draw two lines from one point and determine the angle between them?
Thanks in advance.
You have to calculate the new coordinates thanks to the law of cosines.
http://en.wikipedia.org/wiki/Law_of_cosines
Once you have calculated the angle, you have to be careful because you will get an absolute angle.
Don't hesitate if you need more help. I also have to do this calculation using KineticJS.
Good luck !
The JS Math Object will be useful I guess : http://www.w3schools.com/jsref/jsref_obj_math.asp

LibGDX - The best way detect colission

I have an airplane. I use rectangle for bounding this airplane to detect collision and it works great. When the airplane begin falling down I rotate airplane's texture, but rectangle remains unchanged. I don't know how to rotate it. I need to rotate it with airplane's texture because my shell doesn't collide the airplane's tail and cabine.
How to rotate rectangle or perhaps create polygon shape to wrap all airplane? Any help will be appreciated!
#jellyfication's answer points to raycasting, but a different and also simple approach you could implement is the Separating Axis Theorem. The links below will show you in detail what the algorithm is about and how to implement it. They also have some interactive demos so you get the 'feel' for what the algorithm is doing.
http://www.metanetsoftware.com/technique/tutorialA.html
http://www.sevenson.com.au/actionscript/sat/
http://www.codezealot.org/archives/55 (this one has a lot of code)
http://gamedev.tutsplus.com/tutorials/implementation/collision-detection-with-the-separating-axis-theorem/
Good luck!
Use the polygon class to and draw your bounding Box.
Then within the polygon class there is a method to rotate.
Rotate and move the polygon with the plane.

polyline with gradient

Is there a way to draw a line along a curved path with a gradient that varies in a direction perpendicular to the direction of the line? I am using the GDI+ framework for my graphics.
The simple answer is no. You can create a GraphicsPath in order to describe what you would like to draw, using AddPoint/AddLine/AddBezier and so forth as needed to describe the complex path of what you want to draw. When you draw the path you can provide a Brush which can be something like LinearGradientBrush or RadialGradientBrush. Neither of those gradient brushes reacts to the actual path being drawn in the sense of changing direction as the drawing occurs. You have to specify the angles etc as constant for the entire gradient area.
One possible method you can use is to set the clip region of the Graphics object to be that of the line only. Then draw a Linear Gradient over the extremes of the line e.g.
GraphicsPath gp = new GraphicsPath();
gp.AddArc(); // etc...
graphics.SetClip( gp );
graphics.FillRectangle( myLinearGradientBrush, gp.GetBounds());
The above code might give you what you are looking for.

Resources