I am interested in drawing the solution for various ODEs and PDEs - ode

How to draw the solution y=sinx+c for the ODE dy/dx = cosx?
I tried in excel but did not reach a solution.
I am new to this.
Please help

If you really want to do that in Microsoft Excel, then you can implement, for example, the Euler method for simplicity as follows:
B1 cell : initial value of y, for example, 0
B3 cell : initial value of x, for example, 0
B4 cell : step size, for example, 0.1, which should be sufficiently small
D1 cell : =$B$2
E1 cell : =$B$1
D2 cell : =D1+$B$3
E2 cell : =E1+COS(D1)*$B$3
Next, select the D2 cell and copy it to D3, D4, ... by dragging the fill handle, up to the point that you want to get. Then, select the E2 cell and copy it to E3, E4, ... by double-clicking the fill handle. This gives (x, y) data in D and E columns, and you can make a plot with them. The above initial values correspond to c=0 in your equation.

Related

draw arc on map with any projection

I want minimize of usage of projection function to draw arc on plane.
As input of algorithm I have:
latitude and longitude of center C
radius R (orthodromic distance)
azimuth of begin of arc according to center A1
azimuth of end of arc according to center A2
projection function proj that take latitude longitude and give x and y on plane,
this function is continuous and has derivative, and its derivative is continuous
proj^-1 function that inverse proj
Output: array of points x, y on plane such is that their original lat, lon = proj^-1(x, y) has orthodromic distance ~ R and azimuth lay between A1 and A2.
In such algorithm I want reduce calls to proj.
At now I can only imagine such slow and not accurate algorithm:
P1 = direct geodetic problem(C, R, A1)
P1_plane = proj(P1)
P1_plane_shift = P1_plane.x + 1, P1_plane.y + 1
P1_shift = proj^-1(P1_plane_shift)
A1_shift = inverse geodetic problem(P1_shift)
dA = A - A1_shift
after that I run cycle from A1 to A2 with dA step using direct geodetic problem helper function.
Such algorithm have such disadvantages:
Not accurate, because of angle error of proj may change from area near P1 to area near P2 = direct geodetic problem(C, R, A2) [Never see this problem on real-life map projections and with R < 100 kilometer]
Call proj to often, so drawing works to slow for me
Any thoughts of improvements of this algorithm?
Update here is plot of possible input:

I'm implementing the Expanding Polytope Algorithm, and I am unsure how to deduce the contact points from a point on the minkowski difference

I've been reading about the EPA from several sources, but they all seem to abruptly stop being useful after the closest point on the minkowski difference to the origin is located. Most of them say something along the lines of "With this information, we can then generate the local and global contact points and contact tangents," but I don't understand how that is even possible, much less how to do it. I don't see how someone could derive the minuend and subtrahend from a difference alone, and certainly not in a reasonable amount of time. What is the standard solution to this problem?
I am looking to implement this algorithm in 3D, if that changes the answer. Thanks
OP of the blog post here.
The post actually says how to compute the contact point in step 8 of the EPA algorithm:
Project the origin onto the closest triangle. This is our closest
point to the origin on the CSO’s boundary. Compute the barycentric
coordinates of this closest point with respect to the vertices from
the closest triangle. The barycentric coordinates are coefficients of
linear combination of vertices from the closest triangle. Linearly
combining the individual support points (original results from
individual colliders) corresponding to the vertices from the closest
triangle, with the same barycentric coordinates as coefficients, gives
us contact points on both colliders in their own model space. We can
then convert these contact points to world space.
Allow me to rephrase it here.
Let Ca, Cb, and Cc denote the three vertices of the triangle of the CSO that contains the closest point, denoted Cp, on the CSO boundary to the origin.
Compute the barycentric coordinate (x, y, z) of the triangle for Cp.
x Ca + y Cb + z Cc = Cp
Note that it is required that we keep the original support function results in global space from the two objects (A & B) used to obtain Ca, Cb, and Cc. Let Aa, Ab, and Ac denote the original support function results for object A. Let Ba, Bb, and Bc denote the original support function results for object B.
Ca = Aa + Ba
Cb = Ab + Bb
Cc = Ac + Bc
Using the barycentric coordinate (x, y, z) obtained earlier to linearly combine the original support function results from object A & B, we can compute the contact points on both objects, denoted Ap and Bp:
Ap = x Aa + y Ab + z Ac
Bp = x Ba + y Bb + z Bc
I hope this clarifies the computation process for you.

Setting up collision groups in farseer

I'm trying to set up collision groups in Farseer so that the items in the picture collide as follows:
G1 Collides with All.
B1 and B2 collide with each other and G1, but not R1 or R2
R1 and R2 collide with each other and G1, but not B1 or B2.
I've been playing around with _Body.CollidesWith = Category.Cat1; and _Body.CollisionCategories = ..., but I'm basically just guessing. Haven't really found any usefull examples in the docs, but I might not have been looking in the right place either.
Edit 1:
Ok, so experimenting some more.
Assuming _Body is B1 (and also applied to B2) in the picture, and Cat1 is G1, and Cat2 is all blue items..
_Body.CollidesWith = Category.Cat1 & Category.Cat2;
_Body.CollisionCategories = Category.Cat2;
Should this not then allow B1 to collide with the ground (G1) and all other blues (B# items)?
Applying the above code makes all blue items collide with nothing not even each other...
_Body.CollisionCategories = Category.Cat1 | Category.Cat2;
instead of
_Body.CollisionCategories = Category.Cat1 & Category.Cat2;

Shift trace of polygon by given vector

I need algorithm to get shift trace of given polygon by given 2d-vector.
Given valid polygon with no holes, but possibly concave.
Operation performs on plane, so the result might be a polygon, possibly with holes.
If it simplifies the task, outer polygon is enough.
It looks simple to describe, but I find it complex to realize, so I look for some ready solutions, preferably in c#.
Suppose you have a polygon P given by the points A1, A2, ... , An.
Now you decide to shift it by X on the x-axis and Y on the y-axis.
You can do this to each point individually to get the ending location of the polygon.
Let's call the shifted polygon Q givng by points B1, B2, ... , Bn.
Then all you need to do is draw the following parallelograms:
(A1 A2 B2 B1), (A2 A3 B3 B2), (A3 A4 B4 B3), ... , (An-1 An Bn Bn-1) , (An A1 B1 Bn)
At this point you will have filled in the shape you want.
Some of the parallelograms will overlap, but that is okay, since you are just filling them all in with the same red color.
By doing it this way, you also get your second example to turn out correctly, (the bottom right corner of the hole in the middle should be diagonal, because of the lip sliding into position).

Getting a list of locations within a triangle in the form of x,y positions

Let's say I have a triangle given by the three integer vertices (x1,y1), (x2,y2) and (x3,y3). What sort of algorithm can I use to return a comprehensive list of ALL (x,y) integer pairs that lie inside the triangle.
The proper name for this problem is triangle rasterization.
It's a well researched problem and there's variety of methods to do it. The two popular methods are:
Scan line by scan line.
For each scan-line you require some basic geometry to recalculate
the start and the end of the line. See Bresenham's Line drawing algorithm.
Test every pixel in the bounding box to see if it is in the
triangle.
This is usually done by using barycentric co-ordinates.
Most people assume method 1) is more efficient as you don't waste time testing pixels that can are outside the triangle, approximately half of all the pixels in the bounding box. However, 2) has a major advantage - it can be run in parallel far more easily and so for hardware is usually the much faster option. 2) is also simpler to code.
The original paper for describing exactly how to use method 2) is written by Juan Pineda in 1988 and is called "A Parallel Algorithm for Polygon Rasterization".
For triangles, it's conceptually very simple (if you learn barycentric co-ordindates). If you convert each pixel into triangle barycentric coordinates, alpha, beta and gamma - then the simple test is that alpha, beta and gamma must be between 0 and 1.
The following algorithm should be appropriate:
Sort the triangle vertices by x coordinate in increasing order. Now we have two segments (1-2 and 2-3) on the one side (top or bottom), and one segment from the other one (1-3).
Compute coefficients of equations of lines (which contain the segments):
A * x + B * y + C = 0
A = y2 - y1
B = x1 - x2
C = x2 * y1 - x1 * y2
There (x1, y1) and (x2, y2) are two points of the line.
For each of ranges [x1, x2), (x2, x3], and x2 (special case) iterate over integer points in ranges and do the following for every x:
Find top bound as y_top = (- A1 * x - C1) div B1.
Find bottom bound as y_bottom = (- A2 * y - C2 - 1) div B2 + 1.
Add all points between (x, y_bottom) and (x, y_top) to the result.
This algorithm is for not strictly internal vertices. For strictly internal vertices items 3.1 and 3.2 slightly differ.
I suppose you have a list of pairs you want to test (if this is not what your problem is about, please specify your question clearly). You should store the pairs into quad-tree or kd-tree structure first, in order to have a set of candidates which is small enough. If you have few points, this is probably not worth the hassle (but it won't scale well if you don't do it).
You can also narrow down candidates further by testing against a bounding box for your triangle.
Then, for each candidate pair (x, y), solve in a, b, c the system
a + b + c = 1
a x1 + b x2 + c x3 = x
a y2 + b y2 + c y3 = y
(I let you work this out), and the point is inside the triangle if a b and c are all positive.
I like ray casting, nicely described in this Wikipedia article. Used it in my project for the same purpose. That method scales on other polygons too, including concave. Not sure about the performance, but it is easily coded, so you could try it yourself (I had no performance issues in my project)

Resources