Android - Detect new direction (left/right) after every GPS update - java

I need to calculate the new direction relative to the previous one at every GPS update by using coordinates. The only thing which is important here is left or right.
First I tried doing this by using the heading only, by just looking at the new heading if it was more to the west or east relative to the previous heading.
But after getting past 0 or 360 degrees point, problems occurred. This also did not seem like a very robust solution.
After 3 GPS updates there is always an array available of the latest 3 GPS coordinates.
The following coordinates should all show left, since it is on a roundabout:
58.70265614,12.45208851
58.70266725,12.45198338
58.7026786,12.4518954
58.70267177,12.45180805
58.70264375,12.45171462
58.70259777,12.45164779
58.70254734,12.45163389
58.7025029,12.45167082
58.70246575,12.45173065
58.70245399,12.45182545
58.7024728,12.45192582
58.70251695,12.45201489
58.70256638,12.45205355
58.70261456,12.45204386
58.70265059,12.45198956
58.70266192,12.45188943
I have difficulties looking at coordinates and see them as or convert them to Points or Vectors, and use this as the base to do calculations.
I did look into similar topics in C++ and C#, but I could not get it translated into my problem.
Also I don't need the complete solution. Pseudo code should be enough as long as the math is there. :)
Thank you for your time!

Related

How to search nearby coordinates in android using google map

I'am new in android development my problem is.
I have to find nearby coordinates from a data in a given radius in android.
For example when i click a button. It will search nearby coordinates listed in an array or in a database.
Example: My current coordinates is 1.1
Nearby coordinates will show : 1.2,1.3,1.4,1.5 which is stored or from my database/array.
Is this possible? Can someone help me. Any answer is really appreciated.
Thanks!
One approach is to simply use a geographical distance function.
Have a look at: http://www.movable-type.co.uk/scripts/latlong.html
This will give you some background information on what you are trying to do. I've used this website many times during work with UAVs. Also, keep in mind that you might need to convert to/from Deg/Min/Sec Lat & Longitude <-> decimal Latitude/Longitude.
Find the method for calculating distance - and there are many coded examples already out there - and then run each of your target points through it to find out how far each is from you.
Good luck!

How to do a wave effect line in java?

I am doing a game like Geometry dash in java , I almost do all of the mechanics but I cant achieve wave effect , I try using a arrylist of lines then draw then in the points of my arrow , but it dint work or maybe I'm very confused
here is a capture of how look right now:
When I press X the arrow goes up and leave a diagonal trace (line) then if I released x its goes down I another line appear in the point of the last line , that whats is look like a wave effect of curves
here is a link of wave mechanic in geometry dash
[geometry dash wave effect][2]
Does I need to use sine wave? becaus its graph look pretty similar but I am not confident about that
I'm having a lot of problems with this mechanic and hope someone could helpe me with any idea and support
thanks for your idea i already solved it ! i finally get the wave effect c: , i draw the lines between the points of my arrow using a normal array
capture3
Don't store lines. Store points. Then draw lines between those points. At a minimum that'll stop it from breaking. Typically you're going shift those points to the left repeatedly at the same speed as the board gets shifted. You're just messing up the math, but, with points it'll at least make it very clear what you're actually getting wrong as well as keeping a contiguous set of lines.
It's not a sine wave or some bezier curves, it's a bunch of line segments as points for the previous position of your ship or whatnot changes.

how to detect this specific movement gesture via sensors?

I'm working on an Android project. it's goal is to detect predefined movement gesture of the device. if the device rotates 45 degrees over an axis(X,Y or Z) and then rotates back to its first position( the first and second positions are not going to be accurate, I mean if it was rotated 50 degrees instead of 45, not important !!!)then the gesture has happened and the app should detect it.
I tried to do that using Accelerometer and Magnetic sensors of device to continually monitor the orientation of the device and detect gesture but the results weren't acceptable(explained here). any start point or idea please ?
It doesn't seem like anybody is going to provide a concrete and valuable answer. So let me try to do that.
First of all, even a bit primitive and straightforward approach allows to spot the fact you do not need to process all the data coming from sensors. Moreover humans are not that fast, so there is no need to proceed 10000 values per second in order to identify any specific move as well.
What you actually need is just to identify key points and make your decision. Does it sound like a tanget to you?
What I'm actually suggesting is to test your solution using an ordinary mouse and available gesture recognition framework. Because the actual idea is pretty much the same. So please check:
iGesture - Gesture Recognition Framework
Mouse Gestures
It such a way it might be easier to develop a proper solution.
Update
Let's imagine I'm holding my phone and I need to rotate it 90 degrees counterclockwise and then 180 degrees clockwise. I hope you will not expect me to do some complex 3D shapes in the air (it will break usability and frankly I do not want to loose my phone), so it is possible to say there might be a point we can track or we can easily simulate it.
Please see my other answer in order to see simple, but working solution of a similar problem:

Calculating a point in 3D space

I am trying to locate a point in 3D space relative to the origin (0,0,0). I have 3 values to calculate this point with: a rotation in degrees about both the x and y axis as well as a "view distance". Using these values, how can I locate a point in 3D space relative to the origin? I have tried using basic trigonometric functions, but the results seem to be random. The image below gives a visual as to what needs to be done.
'vd' being the "view distance"
'c' being a value holder
'(x,y,z)' being the coordinate I am trying to find
What I am trying to do is find the point a player is looking at a certain distance away (find a point in the direct line of sight of the player out a certain distance). Keep in mind, the rotations about the x and y axis are constantly changing, but the view distance remains the same. If anyone has any suggestions, methods of how to do this, or needs clarification, please comment/answer below.
I am doing this in LWJGL, and the code I am using is as follows:
float c = (float)(Math.cos(Math.toRadians(A00.rot.y)) * view_distance);
locate.y = (float)(Math.sin(Math.toRadians(rot.y)) * view_distance);
locate.x = (float)(Math.cos(Math.toRadians(rot.x)) * c);
locate.z = (float)(Math.sin(Math.toRadians(rot.x)) * c);
EDIT:
My issue is that this current setup does NOT work for some reason. The math seems legitimate to me, but I must have something wrong somewhere in the actual setup of the graph..
I suggest looking up quaternions. No need to fully understand how they work. You can find ready made classes for java available on the internet as well. Quaternions allow you to represent a rotation in 3D space.
What I would then do, is to start with a vector representing the direction pointing forwards from the origin, and apply the same rotation that the player currently has to it. Now it is pointing in the same direction as the player. Now if you take the player's current point, and the direction vector we now have a ray describing where the player is looking at.
I suggest this link for further information on quaternions. They may look complex but, as I said, you don't need to fully understand how and why they work to be able to use them. Just copy the formulae and learn how they are used. Once you figure out how to use them, they make 3d rotations really easy.
http://content.gpwiki.org/index.php/OpenGL:Tutorials:Using_Quaternions_to_represent_rotation

designing picture puzzle

I am planning to develop a jigsaw puzzle game.
Now I already have images and image pieces, so we don't need algorithm to cut the image in pieces.
On the UI side there would be two sections
First section contains the broken images in random order.
Second section contains the outline of the full image. User need to drag and drop the the cut images onto the outline image.
I am not sure how can the pieces be matched on the the outline image?
Any idea about the algorithm or the starting pointers?
Allow the user to drag each piece into the outline area. Allow the piece to be rotated in 90 degree increments.
Option 1:
If a piece is in the correct location in the overall puzzle, and at the correct angle, AND connected to another piece, then snap it into place with some user feedback. The outside edge of the puzzle can count for a connection to edge pieces.
Option 2:
A neighbor is an adjacent puzzle piece when the puzzle is assembled. When the puzzle pieces are mixed up, they still have the same neighbors. Each puzzle piece (except the edge pieces) has four neighbors.
If a piece is near one of its neighbors at the correct angle relative to that neighbor, then snap it to the other piece. Then allow the two (or more) pieces to be dragged around as a unit, as is done with a single piece. This would allow the user to assemble subsections of the puzzle in any area, much like is done with a physical jigsaw puzzle, and connect the subsections with one another.
You can check the piece being moved to its four neighbors to see if they are close enough to snap together. If a piece has its proper edge close enough to the proper edge of its neighbor, at the same angle, then they match.
There are several ways to check relative locations. One way would be to temporarily rotate the coordinates of the piece you are testing so it is upright, then rotate the coordinates of all its desired neighbors, also temporarily, to the same angle. (Use the same center of rotation for all the rotations.) Then you can easily test to see if they are close enough to match. If the user is dragging a subassembly, then you will need to check each unmatched edge in the subassembly.
Option 2 is more complex and more realistic. Option 1 can be further simplified by omitting the rotation of pieces and making every piece the proper angle initally.
For a regular shapes you can go with a matrix. I recommend this as the first approach. Dividing the puzzle is as simple as defining X,Y dimensions of the matrix. For each piece you have a series of four values then, one for each side, saying whether it is flat, pointing out, or pointing in. This will give you a very classic jigsaw puzzle setup.
How the pieces actually look becomes a strict GUI thing. Now, for the first draft I recommend getting it working with perfectly square pieces. Taking rectangular bits of an image should be easy to do in any GUI framework.
To go to shaped pieces you'll need a series of templates. These will become masks that you apply to the image. Each mask clips out a tiny portion of the image to produce your piece. You'll probably need to dynamically create the masks in order to fit them to the puzzle. At first start with simply triangular connections. Once you have that working you can do the math to get nice bulbous connector shapes. Look up "clip" and "mask" in your GUI framework.
If you wish to do irregular polygon shapes that don't follow a general matrix layout, then you need to do a lot more work. This is why I recommend getting the square first working as a good example. Now you'll need to delve into graph theory and partitioning. Pick up some books on 3D programming -- focusing on algorithms, as they do partitioning all the time. Though I wouldn't doubt if there is a book with this exact topic in it.
Have fun.
the data structure is simple I guess- each peace will point to it's neighbors and will hold the actual shape to display.
on the MMI (UI) of the app - what is your developing environment ?
If it's windows - I would go with c# and winforms or even better wpf.
if it's unix, you'll have to get someone else's advise, as I'm not an expert there.
1) How to break image into random polygons
It seems that you have figured out this part. (from : "Now I already have images and image pieces, so we don't need algorithm to cut the image in pieces.")
2) what kind of data structure can solve the problem
You can create a Class Piece like Scribble class in this example and your pieces would be array of objects of Piece class.
So, you will have two arrays,
(i) actual image pieces array
(ii) image piece outline array
So, whenever you drag and drop one piece on to the full outline of image, it will check whether the image piece object is intersecting more than 80% and ID (member variable of Piece object) of actual image piece and image piece outline matches, then you got the right piece at right place...
3) UI implementation
Check this out.
You could make an array of objects of the class "PuzzleTile"
Every such tile has an image and an integer
After every move, check if the integers are sorted correctly, means:
123
456
789
You could make a function for that which returns a bool.
Note: I'm currently developing under C#, that's why it's probably easiest to realize especially this concept under C#, although other platforms need none up to barely some modification to this.

Categories