Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 3 years ago.
Improve this question
How do you get the azimuth and elevation from one enu vector to another enu vector?
A link to a formula or piece of code would be helpful. I'm not getting much information at all when searching.
You can calculate the azimuth and elevation angles between East-North-Up vectors (x,y,z) and (u,v,w) using the following:
Subtract the vectors: (x,y,z) - (u,v,w) = (x-u,y-v,z-w) = (x',y',z')
Compute the azimuth angle: a = arctan(x'/y') = arctan((x-u)/(y-v))
Compute the elevation angle: e = arctan(z'/y') = arctan((z-w)/(y-v))
In Python:
v1 = np.array([3,4,4])
v2 = np.array([1,2,6])
v = v1 - v2
a = np.degrees(np.arctan(v[0]/v[1]))
e = np.degrees(np.arctan(v[2]/v[1]))
print('azimuth = '+str(a)+', elevation = '+str(e))
Output:
azimuth = 45.0, elevation = -45.0
(Image Source)
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I have a picture with normalized coordinates ((-1, -1), in the top left corner, (0, 0) in the center, (1, 1) in the bottom right) and i want an function to output a 0 at the corners and a 1 in the center. I have tried some f(x,y) = 1 - max(abs(x), abs(y)) but that produces sharp corners:
What function produces a more round output, rather than this pyramid-like function?
Your function is using the squared distance to the origin. A smoother version would use the distance itself. Also note that your formula -(1/sqrt(2)*x)**2-(1/sqrt(2)*y)**2 + 1 can be simplified to 1 - (x**2 + y**2) / 2.
Here is a comparison between the squared distance (at the left), the distance itself (at the center) and one of the formulas proposed by #MadPhysicist (at the right). The image is made a bit larger to better illustrate what's happening near the borders. A contour plot is used to show how the values are smoothed out:
import numpy as np
import matplotlib.pyplot as plt
k = 1.2
x, y = np.meshgrid(np.linspace(-k, k, 100), np.linspace(-k, k, 100))
sqrt2 = np.sqrt(2)
fig, axes = plt.subplots(nrows=2, ncols=3, figsize=(12, 6))
for i, axrow in enumerate(axes):
for j, ax in enumerate(axrow):
if j == 0:
f = -(1 / sqrt2 * x) ** 2 - (1 / sqrt2 * y) ** 2 + 1 # f = 1 - (x**2 + y**2) / 2
elif j == 1:
f = 1 - np.sqrt(x * x + y * y) / sqrt2
else:
s = 0.65
f = np.exp(-0.5 * (np.sqrt(x * x + y * y) / s) ** 2)
img = ax.imshow(f, cmap='Greys_r', extent=[-k, k, -k, k], vmin=0, vmax=1)
if i == 0:
img = ax.contour(x, y, f, levels=np.linspace(0, 1, 11), cmap='inferno_r')
ax.axhline(1, color='red', ls=':')
ax.axhline(-1, color='red', ls=':')
ax.axvline(1, color='red', ls=':')
ax.axvline(-1, color='red', ls=':')
plt.colorbar(img, ax=ax)
plt.tight_layout()
plt.show()
Since you don't seem to be concerned with unbounded drop-off along the edges, a parabola is definitely one possible option, as you discovered. In fact any monotonic function can be used to generate a "cone" of that type, by applying it to the radius:
f(r) = 1 - r/sqrt(2)
r = sqrt(x^2 + y^2)
This gives a linear cone. Your answer is equivalent to
f(r) = 1 - (r/sqrt(2))^2
You can increase the power of r all you want to get similar results, with a more spread-out central region and sharper drop-offs. Taking powers smaller than one will sharpen the peak in the center.
A more typical function to use in this case would be a Gaussian. You would not necessarily have zeros in the corners, but this is a ubiquitous function you should probably know about:
f(r) = exp(-0.5*(r/s)^2)
Here s, the standard deviation of the spread, determines the width of the peak.
Found it. I had to use a quadratic equation like this:
f(x,y)=-(1/sqrt(2)*x)**2-(1/sqrt(2)*y)**2 + 1
That produces a nice vignette like this
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
and I'm having difficulty to drawing a line on the screen using the X, Y, Z coordinates of a CSV or TXT file. I tried with the line render and also with swipe trail, but I could not. Thanks for your help
Read a file e.g using StreamReader.ReadToEnd
var fileContent = "";
(using var reader = new StreamReader(path))
{
fileContent = reader.ReadToEnd();
}
Assuming a CSV/txt content like
23.46, 1.0, 2.4
0.003, 7.038, 3
...
Parse the content e.g. using SplitCSVLine from CSVReader
private static string[] SplitCsvLine(string line)
{
return (from System.Text.RegularExpressions.Match m in System.Text.RegularExpressions.Regex.Matches(line,
#"(((?<x>(?=[,\r\n]+))|""(?<x>([^""]|"""")+)""|(?<x>[^,\r\n]+)),?)",
System.Text.RegularExpressions.RegexOptions.ExplicitCapture)
select m.Groups[1].Value).ToArray();
}
use it together with float.TryParse(string, out float) like
var lines = fileContent.Split('/n');
var points = new List<Vector3>();
foreach(var line in lines)
{
var parts = SplitCsvLine(line);
float x = float.TryParse(parts[0], out x) ? x : 0;
float y = float.TryParse(parts[1], out y) ? y : 0;
float z = float.TryParse(parts[2], out z) ? z : 0;
points.Add(new Vector3(x, y, z));
}
where
float x = float.TryParse(parts[0], out x) ? x : 0;
is a short form of writing
float x;
if(!float.TryParse(parts[0], out x))
{
x = 0;
// Alternatively you could also declare this point as invalid
// and not add this point at all
continue;
}
or, if you know the content will only exactly contain those numeric symbols and commas, no special characters, you could also simply use
var parts = line.Split(',');
And finally apply those points e.g. to a LineRenderer using SetPositions
GetComponent<LineRenderer>().SetPositions(points);
There might be more efficient options though.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
some elegant way to create a shadow trail of a object ,e.g a plane?
this answer i can't understand this ,im a starter for as3 .
so , some directly code should be very good for me .
var dis : DisplayObject;
var prevDis : DisplayObject;
for ( var i:int = _displayList. length -1; i >= 1; i-- ) //reverse recursive
{
dis = _displayList[ i ];
prevDis = _displayList[ i -1 ] ;
dis . x = prevDis .x;
dis . y = prevDis .y; //create ghost shadow effect
}
// need to locate the first displayObject's position by tween .
prevDis . x = int (_tween . target. x );
prevDis . y = int (_tween . target. y );
_tween . tick( delta );
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'm trying to write two inverse functions.
If we pass to function A value 10 it returns for example 4,86 and if we pass that number to function B it should give us back original 10.
I'm using something like this in function A:
output = sqrt(inputForA / range) * inputForA;
So is it possible to reverse it in function B and calculate inputForA only knowing output and range.
You just need to factor that equation to single out inputForA. Here are the algebraic steps:
output = sqrt(inputForA / range) * inputForA
output / inputForA = sqrt(inputForA / range)
sq(output) / sq(inputForA) = inputForA / range
range * sq(output) / sq(inputForA) = inputForA
range * sq(output) = cube(inputForA)
So the cube root of range times the output squared should give you your original input. I don't have a good way of showing that in here though...
You just have to use basic math. output = pow(inputForA, 3. / 2.) * pow(range, 1. / 2.) so inputForA = pow(output * pow(range, 1. / 2.), 2. / 3.). This only works if inputForA and scale have the same sign, but the first function is only defined on that interval, so this is okay (since sqrt is only defined for positive values).
In Python:
scale = 7.
def f(x):
return math.sqrt(x / scale) * x
def g(y):
return math.pow(y * math.pow(scale, 1. / 2), 2. / 3)
print g(f(10))
10.0
print f(g(10))
10.0
You could also have used Wolfram alpha to get the answer:
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
If I have a programming language with first class functions. What should the semantics be when a generator function is shared?
For example:
var f = function() {
foreach (i in 0..42)
yield i;
}
int a = f(); // 0
int b = f(); // 1
// Assigning the generator function
var g = f;
int c = g(); // ??
int d = f(); // ??
I can imagine three things:
c == 2, d == 3 meaning that the generator function is shared
c == 0, d == 2 meaning that a new generator function is created, with the values initialized
c == 2, d == 2 meaning that a new generator function is created by copying the current state of the generator
The best answer in my opinion, would provide the most compelling argument to do one mechanism or another. Often I find that prior art is the most persuasive argument.
If you have reference semantics in your language, and assignment is usually reference assignment, then you want option 1.
This is what happens in Python, where generates are objects, and assignment is reference assignment (even though you invoke .next() to retrieve the next value, rather than "calling" the generator).
Here is a brief demonstration how this behaves in Python:
>>> def gen():
... for i in range(42):
... yield i
...
>>> f = gen().next
>>> a = f()
>>> b = f()
>>> g = f
>>> c = g()
>>> d = f()
>>> a, b, c, d
(0, 1, 2, 3)