equivalent of getbounds - google-maps-api-3

What is the equivalent of map.getbounds() with the V3 ?
I suppose I must use b = new google.maps.LatLngBounds(pt1,pt2)
with pt1 and pt2 the origin and the end of the map ?

It is map.getBounds()
See http://code.google.com/apis/maps/documentation/javascript/reference.html#Map

Related

How to create a 3D vector using XYZ angles

So i found out how to create a vector2 in 2D using only one angle but now i need a vector3 using two or three angles
The code i used to get the 2D vector:
function V2ToForce(Angle,Force)
local Force = Force or 1
local X,Y = math.cos(Angle)*Force,math.sin(Angle)*Force
return X,Y
end
Any pseudocode would help.
Edit:
I found this formula but dosent work either
function Test(X,Y,Force)
local x = math.cos(X) * math.cos(Y);
local z = math.sin(X) * math.cos(Y);
local y = math.sin(Y);
return x*Force,y*Force,z*Force
end
Ty who commented got it to work, still has some bugs but nothing that a if statement can't solve.
Thats what i ended up with for anyone with the same problem
function Test1(X,Y,Force)
local X1 = math.cos(Y)*Force
local Y1 = (math.sin(Y)*math.sin(X))*Force
local Z1 = (-math.sin(Y)*math.cos(X))*Force
return X1,Y1,Z1
end
function Test2(X,Y,Force)
local X1 = math.cos(X) * math.cos(Y)
local Z1 = -math.sin(X) * math.cos(Y)
local Y1 = math.sin(Y)
return X*Force,Y*Force,Z1*Force
end
Sry for my bad english

How to extract a certain element from a dictionary

For example:
d = [{'symbol': 'ETH', 'available': '1'}, {'symbol': 'DOGE', 'available': '4'} , {'symbol': 'USD', 'available': '10'}]
I need to extract the available USD which is 10 in the above dictionary, could you please provide me with a proper code?
You can use next() built-in method:
out = next(dct["available"] for dct in d if dct["symbol"] == "USD")
print(out)
Prints:
10
Well, if your language is python you can do:
print([x for x in d if d['symbol'] == 'USD'][0]['available'])
Do keep in mind that USD must exist in the list for it to work.

Julia: U factor in Cholesky factorization is not a field?

Suppose that I have the following
> L = [5 1; 1 3]
> chol = LinearAlgebra.cholesky(L)
LinearAlgebra.Cholesky{Float64,Array{Float64,2}}
U factor:
2×2 LinearAlgebra.UpperTriangular{Float64,Array{Float64,2}}:
2.23607 0.447214
⋅ 1.67332
I want to access the matrix and more specifically slice the matrix and get the first row, second row, etc, so I can access the factor U like this
> chol.U
2×2 LinearAlgebra.UpperTriangular{Float64,Array{Float64,2}}:
2.23607 0.447214
⋅ 1.67332
My question is: what exactly does .U stand for? If I try getfield(chol, :U) I get an error because there is no field :U and indeed, fieldnames(LinearAlgebra.Cholesky) returns :factors, :uplo and :info.
What am I missing here?
In Julia 1.0 the dot syntax x.s is shorthand for getproperty(x, :s) just like x[idx] maps to getindex(x, idx). Hence, you can make it behave in whatever way you want. Only the generic default is equivalent to lettings you access an object's fields. To see the particular method that is called for objects of type Cholesky you can use #which as follows:
julia> #which chol.U
getproperty(C::Cholesky, d::Symbol) in LinearAlgebra at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.0\LinearAlgebra\src\cholesky.jl:339
If you check the source code in cholesky.jl:339 you find the following:
function getproperty(C::Cholesky, d::Symbol)
Cfactors = getfield(C, :factors)
Cuplo = getfield(C, :uplo)
info = getfield(C, :info)
if d == :U
return UpperTriangular(Cuplo === char_uplo(d) ? Cfactors : copy(Cfactors'))
elseif d == :L
return LowerTriangular(Cuplo === char_uplo(d) ? Cfactors : copy(Cfactors'))
elseif d == :UL
return (Cuplo === 'U' ? UpperTriangular(Cfactors) : LowerTriangular(Cfactors))
else
return getfield(C, d)
end
end
We see that in the case d == :U it does not map to something like getfield(C, d) but instead constructs a UpperTriangular matrix in some way. Only for some generic symbol d does the method map to getfield(C, d).
Lastly, the pendant of fieldnames for fields is propertynames for properties (things that you can write for s in x.s):
julia> propertynames(chol)
(:U, :L, :UL)
julia> fieldnames(typeof(chol))
(:factors, :uplo, :info)
As you can see the two concepts, fields and properties, can be orthogonal. In this case, there is no direct overlap.

Find specific point between 2 points - three.js

How can I find a point ( C (x,y,z) ) between 2 points ( A(x,y,z) , B(x,y,z) ) in a thgree.js scene?
I know that with this: mid point I can find the middle point between them, but I don't want the middle point, I want to find the point which is between them and also has distance a from the A point?
in this picture you can see what I mean :
Thank you.
Basically you need to get the direction vector between the two points (D), normalize it, and you'll use it for getting the new point in the way: NewPoint = PointA + D*Length.
You could use length normalized (0..1) or as an absolute value from 0 to length of the direction vector.
Here you can see some examples using both methods:
Using absolute value:
function getPointInBetweenByLen(pointA, pointB, length) {
var dir = pointB.clone().sub(pointA).normalize().multiplyScalar(length);
return pointA.clone().add(dir);
}
And to use with percentage (0..1)
function getPointInBetweenByPerc(pointA, pointB, percentage) {
var dir = pointB.clone().sub(pointA);
var len = dir.length();
dir = dir.normalize().multiplyScalar(len*percentage);
return pointA.clone().add(dir);
}
See it in action: http://jsfiddle.net/8mnqjsge/
Hope it helps.
I know the question is for THREE.JS and I end up looking for something similar in Babylon JS.
Just in case if you are using Babylon JS Vector3 then the formula would translate to:
function getPointInBetweenByPerc(pointA, pointB, percentage) {
var dir = pointB.clone().subtract(pointA);
var length = dir.length();
dir = dir.normalize().scale(length *percentage);
return pointA.clone().add(dir);
}
Hope it help somebody.
This is known as lerp between two points
e.g. in Three:
C = new Three.Vector3()
C.lerpVectors(A, B, a)
also in generic this is just a single lerp (linear interpolation) math (basically (a * t) + b * (1 - t)) on each axis. Lerp can be described as follows:
function lerp (a, b, t) {
return a + t * (b - a)
}
in your case (see above) :
A = {
x: lerp(A.x, B.x, a),
y: lerp(A.y, B.y, a),
z: lerp(A.z, B.z, a)
}

Assistance with Lua Cosine, wrong results returned

Ok, first up, this is NOT for a class, test, or other student type activity.
I'm a scripter for a game, and am trying to implement the math library for all to use, and unfortunately, all I have available to me is very basic lua. The implemented version cannot be changed, and does not include any libraries. For those wondering, its for scripting in Fold.It.
Here's what I have...
math={}
math.fact = function(b) if(b==1)or(b==0) then return 1 end e=1 for c=b,1,-1 do e=e*c end return e end
math.pow = function(b,p) e=b if(p==0) then return 1 end if(p<0) then p=p*(-1) end for c=p,2,-1 do e=e*b end return e end
math.cos = function(b,p) e=0 p=p or 10 for i=1,p do e=e+(math.pow(-1,i)*math.pow(b,2*i)/math.fact(2*i)) end return e end
To clarify above, math.fact returns factorial, which is returning accurate to about 10 points of precision, and is a new function I've done to aid in cosine calculation.
The math.pow is also a new function to handle returning powers, also working as expected.
The issue is with the cosine function. Its returning unexpected values. Here's an easier to digest version (I've been writing my library stuff ultra lean)...
function math.cos(value,precision)
result=0
precision=precision or 10
for i=1,precision do
result=result+(math.pow(-1,i)*math.pow(value,2*i)/math.fact(2*i))
end
return e
end
The problem is, with those functions, for print(math.cos(90)) it returns 4.77135... when I'm expecting -0.44807... (based on calc in scientific mode, or using an online tool to cos(90)).
I'm also having issues with sin and tan, however they are similarly written to cos, which seems to have been done in many languages. If I can figure out what I'm doing wrong, I can get them all fixed.
EDIT: Corrected typo
First, your lua doesn't run. Second, you need to make your variables local. Third, cosine starts with a one.
The problem is because the Taylor series you are using only converges on the correct values of cosine close to zero. You would have to use a far more terms of the series to get it to handle 90 correctly. You can fix this for your implementation two ways:
Add a pi constant. Then use a while loop to adjust the value such that abs(value) < 2*pi:
math.pi = 3.14159265358
while value > math.pi*2 do
value = value - math.pi * 2
end
while value < -math.pi*2 do
value = value + math.pi * 2
end
Or - find or implement a version of fmod in lua.
Here is the corrected code (you can minify it):
math={}
math.fact = function(b)
if(b==1)or(b==0) then
return 1
end
local e=1
for c=b,1,-1 do
e=e*c
end
return e
end
math.pow = function(b,p)
local e=b
if(p==0) then
return 1
end
if(p<0) then
p=p*(-1)
end
for c=p,2,-1 do
e=e*b
end
return e
end
math.cos = function(b,p)
local e=1
b = math.correctRadians(b)
p=p or 10
for i=1,p do
e=e+(math.pow(-1,i)*math.pow(b,2*i)/math.fact(2*i))
end
return e
end
math.pi = 3.1415926545358
math.correctRadians = function( value )
while value > math.pi*2 do
value = value - math.pi * 2
end
while value < -math.pi*2 do
value = value + math.pi * 2
end
return value
end
interactive lua run:
imac:~ root$ lua -i temp.lua
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> print( math.cos( 90 ) )
-0.44807359244883
>

Resources