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.
What algorithms are used to find gaps between adjacent polygons (example pictures show 2 adjacent polygons and a shaded 'gap' between them), and is there a common name for this type of operation? Polygons in my input may have coincident vertices, segments, both, or neither. Polygons are represented as ordered lists of points. Adjacent polygons are defined as having at least one coincident point or segment.
I am developing in Go (and have access to the GEOS library), but any references to algorithm steps or implementations in common languages would be helpful.
This might not be what you were looking for, but something like this might get the job done.
Suppose you can calculate a list of all points of intersection p1, p2, …, pk between the perimeters of the two polygons. Let v1, v2, …, vn be the vertices of the first polygon, and w1, w2, …, wm be the vertices of the second polygon.
First, create two ordered collections c1 and c2, where c1 contains p1, p2, …, pk and v1, v2, …, vn, in order (so that if going around the perimeter of the polygon in the clockwise direction, the vertices appear in the list in the order visited), and c2 contains p1, p2, … pk and w1, v2, …, vm ordered in the same way.
Now, between every two adjacent p(i%k) and p((i+1)%k) there is some overlap or gap. This overlap or gap may be degenerate iff the vertices appearing in c1 and c2 between these two points of intersection are the same; in this case, the polygon traced out has area zero and may be discarded. Otherwise, we must see whether the vertices in c1 and c2 appearing between the points of intersection define a gap or an overlap.
If we have an easy/cheap way of testing whether a point is contained within the original polygon, simply choose a point in the space (e.g., the center of the triangle formed by one of the points of intersection and each of the adjacent points in c1 and c2 is guaranteed to be inside the space) and see whether the point is included in either c1 or c2 (it cannot be in one and not the other; why?). If the point is included, then you have an overlap; otherwise, you have a gap.
Indeed, we do have an easy way. If we are going around the first polygon in clockwise order, then if the point identified above (the middle of the triangle so described) is to the right of the line segment formed by the point of intersection and the vertex in c1 adjacent to it, then it's an overlap; otherwise, it's a gap. Alternatively, you can go clockwise around the points in c2 and use the same rule to tell.
To see whether a point is to the left or right of a vector:
take the vector (e.g., the point of intersection to the adjacent point in either c1 or c2)
take the vector to the candidate point (e.g., the center of the triangle described earlier)
Compute the 3-dimensional cross product
The sign of the z-coordinate of the resulting vector gives the answer.
In this example:
p1, p2, p3 ~ (3.1, 5.5), (3.3, 4), (3.8, 2)
v1, v2, v3, v4, v5 ~ (1, 0), (1, 8), (4, 4.5), (2, 3), (3.8, 2)
w1, w2, w3, w4 ~ (4, 1), (3, 5), (4, 9), (9, 5)
c1 ~ (v1, v2, p1, v3, p2, v4, p3=v5)
c2 ~ (w1, p3, p2, w2, p1, w3, w4)
pairs of points of intersection adjacent in c1:
x1 = (p1, p2), x2 = (p2, p3), x3 = (p3, p1)
pairs of points of intersection adjacent in c2:
y1 = (p3, p2), y2 = (p2, p1), y3 = (p1, p3)
triangle for x1 has vertices (p1, v3, w2), middle is
~ ((3.1+4+3)/3, (5.5+4.5+5)/3) = (3.3, 5)
vector from p1 to v3 ~ (0.9, -1)
vector from p1 to middle of triangle ~ (0.2, -0.5)
cross product of p1-v3 x middle of triangle vector:
+0.9 -1.0 +0.0
+0.2 -0.5 +0.0
i j k
=> -0.45k
this has a negative sign, so this is an overlap
triangle for x2 has vertices (p2, v4, p3=v5), middle is
~ ((3.3+2+3.8)/3, (4+3+2)/3) = (3, 3)
vector from p2 to v4: (-1.3, -1)
vector from p2 to middle of triangle: (-0.3, -1)
cross product of p2-v4 and middle of triangle vector:
-1.3 -1.0 +0.0
-0.3 -1.0 +0.0
i j k
=> 1.3k
this has a positive sign, so this must be a gap
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;
I have 27 cubes (made of C0, C1, ..., C26) in my scene, but I would like to get a group with all of them (named GAll), and two other groups : G1(made of C0, C3, C6, C9, C12, C15, C18, C21, C24) and G2(made of C0, C1, C2, C3, C4, C5, C6, C7, C8). Indeed, all these groups needs different rotation operations.
The problem is that I can only add a mesh to only one parent at the same time. Is there a way, for example, to :
add C0 to the scene
add C0 to the whole cube group
add C0 to the group G1
add C0 to the group G2
going against the "One parent only per child" ?
Why ? Because I am trying to build a Rubik's Cube, so that changed made by a group affects all of its meshes for other groups.
Indeed, if I try to add a child to several groups, only the last "added group" will be retained.
I am using Three.js revision 68.
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).