I have a collection with 5400 documents. I kept data from 1 player during a soccer game. Every second i get the long and lat from the player. Now I want the total distance of the player during the game.
Some idea's ?
This is an example of one document:
{
"_id" : ObjectId("59807a01702661033d918e8e"),
"playerId" : 1,
"timestamp" : ISODate("2017-08-01T11:11:45.078Z")
"loc" : {
"type" : "Point",
"coordinates" : [
4.94193,
51.32447
]
}
}
You can fetch all of the points of the player, calculate the distances between them, and sum the distances up.
For the distance calculation, you can use this algorithm(using php, hope that it's fine)
class Geo
{
const R = 6371000;
/**
* #param float[] $point1 latitude and longitude
* #param float[] $point2 latitude and longitude
* #return float
*/
static public function calculateDistance($point1, $point2)
{
$latRad1 = deg2rad($point1[0]);
$latRad2 = deg2rad($point2[0]);
$deltaLat = deg2rad($point2[0] - $point1[0]);
$deltaLon = deg2rad($point2[1] - $point1[1]);
$a = sin($deltaLat/2) * sin($deltaLat/2) +
cos($latRad1) * cos($latRad2) *
sin($deltaLon/2) * sin($deltaLon/2);
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
return self::R * $c;
}
}
Hope it's helpfull.
Related
I have 2 tables 1 is for facility and 1 is for customer. both contained latitude longitude we want query to fetch customer's available with in 1 miles of facility. We don't want to use postgres function like ST_Distance. Any alternate query to achieve it.
Iterate java list of location and used haversine formula to calculate distance in miles
private double distance(double LatOne, double LonOne, double LatTwo, double LonTwo) {
LonOne = Math.toRadians(LonOne);
LonTwo = Math.toRadians(LonTwo);
LatOne = Math.toRadians(LatOne);
LatTwo = Math.toRadians(LatTwo);
double deltaLon = LonTwo - LonOne;
double deltaLat = LatTwo - LatOne;
double formula = Math.pow(Math.sin(deltaLat / 2), 2)+ Math.cos(LatOne) * Math.cos(LatTwo)* Math.pow(Math.sin(deltaLon / 2),2);
double fOutput = 2 * Math.asin(Math.sqrt(formula));
return (fOutput * 3956) ;
}
here is my code I have 3 UITextfields c, d and e and a button to calculate and display the result into a UITextfield called result but I can't get the result to display 2 decimal places.
func getRootValue() {
if let cText = cValue.text, let dText = dValue.text {
if let doubleC = Double(cText), let doubleD = Double(dText) {
let theSquare = sqrt((doubleC * doubleC) + (doubleD * doubleD))
rootValue.text = "\(theSquare)"
eValue.text = String(Double(eValue.text!)!)
myResult = String(Double(rootValue.text!)! * Double(eValue.text!)! * 2)
roofArea.text = String(Double(rootValue.text!)! * Double(eValue.text!)! * 2)
roofArea.text = (NSString(format:"%.2f")) as String
}
}
}
The result is 0.00 so ive finally got 2 decimal places but its not displaying the actual calculation can anyone give me some help
I am trying to convert some data with the indicated measurements package, but I'm not succeeding on it.
My data:
Long Lat
62ᵒ36.080 58ᵒ52.940
61ᵒ28.020 54ᵒ59.940
62ᵒ07.571 56ᵒ48.873
62ᵒ04.929 57ᵒ33.605
63ᵒ01.419 60ᵒ30.349
63ᵒ09.555 61ᵒ29.199
63ᵒ43.499 61ᵒ23.590
64ᵒ34.175 62ᵒ30.304
63ᵒ16.342 59ᵒ16.437
60ᵒ55.090 54ᵒ49.269
61ᵒ28.013 54ᵒ59.928
62ᵒ07.868 56ᵒ48.040
62ᵒ04.719 57ᵒ32.120
62ᵒ36.083 58ᵒ51.766
63ᵒ01.644 60ᵒ30.714
64ᵒ33.897 62ᵒ30.772
63ᵒ43.604 61ᵒ23.426
63ᵒ09.288 61ᵒ29.888
63ᵒ16.722 59ᵒ16.204
What I'm trying:
library(measurements)
library(readxl)
coord = read.table('coord_converter.txt', header = T, stringsAsFactors = F)
# change the degree symbol to a space
lat = gsub('°','', coord$Lat)
long = gsub('°','', coord$Long)
# convert from decimal minutes to decimal degrees
lat = measurements::conv_unit(lat, from = 'deg_dec_min', to = 'dec_deg')
long = measurements::conv_unit(long, from = 'deg_dec_min', to = 'dec_deg')
What I'm getting with this penultimate line:
Warning messages:
In split(as.numeric(unlist(strsplit(x, " "))) * c(3600, 60), f = rep(1:length(x), : NAs introduced by coercion
In as.numeric(unlist(strsplit(x, " "))) * c(3600, 60) : longer object length is not a multiple of shorter object length
In split.default(as.numeric(unlist(strsplit(x, " "))) * c(3600, : data length is not a multiple of split variable
Can someone point my mistake or make a suggestion of how to proceed?
Thank you!
I think the issue here was that after gsub call, degrees and minutes were not space delimited, as required by measurements::conv_unit.
For example, this works fine (for this reproducible example I also changed "ᵒ" to "°"):
library(measurements)
#read your data
txt <-
"Long Lat
62°36.080 58°52.940
61°28.020 54°59.940
62°07.571 56°48.873
62°04.929 57°33.605
63°01.419 60°30.349
63°09.555 61°29.199
63°43.499 61°23.590
64°34.175 62°30.304
63°16.342 59°16.437
60°55.090 54°49.269
61°28.013 54°59.928
62°07.868 56°48.040
62°04.719 57°32.120
62°36.083 58°51.766
63°01.644 60°30.714
64°33.897 62°30.772
63°43.604 61°23.426
63°09.288 61°29.888
63°16.722 59°16.204"
coord <- read.table(text = foo, header = TRUE, stringsAsFactors = F)
# change the degree symbol to a space
lat = gsub('°',' ', coord$Lat)
long = gsub('°',' ', coord$Long)
# convert from decimal minutes to decimal degrees
lat = measurements::conv_unit(lat, from = 'deg_dec_min', to = 'dec_deg')
long = measurements::conv_unit(long, from = 'deg_dec_min', to = 'dec_deg')
yields...
> cbind(long, lat)
long lat
[1,] "62.6013333333333" "58.8823333333333"
[2,] "61.467" "54.999"
[3,] "62.1261833333333" "56.81455"
[4,] "62.08215" "57.5600833333333"
[5,] "63.02365" "60.5058166666667"
[6,] "63.15925" "61.48665"
[7,] "63.7249833333333" "61.3931666666667"
[8,] "64.5695833333333" "62.5050666666667"
[9,] "63.2723666666667" "59.27395"
[10,] "60.9181666666667" "54.82115"
[11,] "61.4668833333333" "54.9988"
[12,] "62.1311333333333" "56.8006666666667"
[13,] "62.07865" "57.5353333333333"
[14,] "62.6013833333333" "58.8627666666667"
[15,] "63.0274" "60.5119"
[16,] "64.56495" "62.5128666666667"
[17,] "63.7267333333333" "61.3904333333333"
[18,] "63.1548" "61.4981333333333"
[19,] "63.2787" "59.2700666666667"
I'm trying to get the closest data from the following data
> db.points.insert({name:"Skoda" , pos : { lon : 30, lat : 30 } })
> db.points.insert({name:"Honda" , pos : { lon : -10, lat : -20 } })
> db.points.insert({name:"Skode" , pos : { lon : 10, lat : -20 } })
> db.points.insert({name:"Skoda" , pos : { lon : 60, lat : -10 } })
> db.points.insert({name:"Honda" , pos : { lon : 410, lat : 20 } })
> db.points.ensureIndex({ loc : "2d" })
then I tried
> db.points.find({"loc" : {"$within" : {"$centerSphere" : [[0 , 0],5]}}})
this time I got different error
error: {
"$err" : "Spherical MaxDistance > PI. Are you sure you are using radians?",
"code" : 13461
then I tried
> db.points.find({"loc" : {"$within" : {"$centerSphere" : [[10 , 10],2]}}})
error: {
"$err" : "Spherical distance would require wrapping, which isn't implemented yet",
"code" : 13462
How to get this done ? I just want to get the closest data based on the given radious from GEO point.
Thanks
A few things to note. Firstly, you are storing your coordinates in a field called "pos" but you are doing a query (and have created an index) on a field called "loc."
The $centerSphere takes a set of coordinates and a value that is in radians. So $centerSphere: [[10, 10], 2] searches for items around [10, 10] in a circle that is 2 * (earth's radius) = 12,756 km. The $centerSphere operator is not designed to search for documents in this large of an area (and wrapping around the poles of the Earth is tricky). Try using a smaller value, such as .005.
Finally, it is probably a better idea to store coordinates as elements in an array since some drivers may not preserve the order of fields in a document (and swapping latitude and longitude results in drastically different geo locations).
Hope this helps:
The radius of the Earth is approximately 3963.192 miles or 6378.137 kilometers.
For 1 mile:
db.places.find( { loc: { $centerSphere: [ [ -74, 40.74 ] ,
1 / 3963.192 ] } } )
I am trying to create particles with three.js, currently as a particle system.
The goal of the project is to create particles, with defined positions and unique IDs, and add an option to select multiple particles and retrieve their IDs.
I did some research, but found only ways to detect the position of a mouse-click.
So, I'm looking for the following information:
First: Is there an option to assign IDs to single particles (as simple as a number)?
Second: Is there a way to select multiple particles and view their IDs in a (popup) window?
Thanks for your Help!
PS: I found, that you can assign IDs to THREE.ParticleDOMMaterial (I don't know, what this function does!?) and THREE.ParticleBasicMaterial (Assign an ID to the material, but not to the particle itself).
All Object3D instances have a unique id in three.js by default and Particle inherits that. Also Object3D has a name property, if that helps.
Here's a little snippet which illustrates naming particles:
for ( var i = 0; i < 100; i++ ) {
particle = new THREE.Particle( new THREE.ParticleCanvasMaterial( { color: Math.random() * 0x808008 + 0x808080, program: program } ) );
particle.name = "particle"+i;
particle.position.x = Math.random() * 2000 - 1000;
particle.position.y = Math.random() * 2000 - 1000;
particle.position.z = Math.random() * 2000 - 1000;
particle.scale.x = particle.scale.y = Math.random() * 10 + 5;
group.add( particle );
}
and here's an example of a mouse down event handler which prints the name and id of the clicked particle in the console:
function onDocumentMouseDown( event ) {
event.preventDefault();
var vector = new THREE.Vector3( ( event.clientX / window.innerWidth ) * 2 - 1, - ( event.clientY / window.innerHeight ) * 2 + 1, 0.5 );
projector.unprojectVector( vector, camera );
var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize() );
var intersects = ray.intersectScene( scene );
if ( intersects.length > 0 ) {
console.log("you clicked particle named '" + intersects[0].object.name + "' with id: " + intersects[0].object.id);
}
}
Goodluck!