How to create square area with format wgs84 meters in arcgis? - format

I can create square in a map but its dimensions are not overlap with wgs84.
For example i created 100m 100m square but map shows square's dimensions are 76.000 74.000 meters.
How can i create this square for map?
Thanks
User entering x and y values and then i got these values to create the vertices of square. But its meters are not overlap with map of wgs84 meters
this.x = xInputElement.valueAsNumber;
this.y = yInputElement.valueAsNumber;
const { x, y } = this.mapView.center;
this.vertices = [[x, y], [this.x + x, y], [this.x + x, -this.y + y], [x, -this.y + y]];
this.addPolygonGraphic(this.vertices);

My mapview's spatial reference is on the image. I think it is not WGS84 but i tried that to write 4326 for spatial reference but then polygon is never creating like that sr of mapview

Related

contour plot in Plotly

With Plotly, I want to plot the contour plot of Z(rho, theta), where rho is the radial and theta is the azimuth coordinates. My first step is to create a meshgrid of rho and theta and calculate the function Z at each grid. I then convert the rho-theta grid to X-Y Cartesian coordinates grid. The Surface plot and its z-projection contour in fig00 are based on X,Y,Z coordinates and are all correct. I have a problem when I want to plot only the contour in fig0.
go.Contour requires one-dimensional x,y coordinates that in Cartesian coordinates are no longer uniform. Moreover, using rho-theta arrays does not produce circular contours as is shown in fig0.
Would anyone be able to assist me with this?
Thank you very much.
'''
dia=9.6
rho = np.linspace(0, dia / 2, 20)
theta= np.linspace(0, 2 * np.pi, 20)
RR, P = np.meshgrid(rho, theta)
X, Y = RR * np.cos(P), RR * np.sin(P)
trace00 = go.Surface(x= X, y= Y, z= ZZ, colorscale=‘rainbow’)
layout00 = go.Layout(title=’ Tear Layer Map’)
fig00 = go.Figure(data=[trace00], layout=layout00)
fig00.update_traces(contours_z=dict(show=True, usecolormap=True,
highlightcolor=“limegreen”, project_z=True))
st.plotly_chart(fig00)
trace0 = go.Contour( x= RR[0,:], y= P[:,0], z= Z, connectgaps=True)
layout0 = go.Layout(margin=dict(l=0, r=0, b=0, t=0))
fig0 = go.Figure(data=[trace0], layout=layout0)
fig0.update_layout(polar_bargap=0)
st.plotly_chart(fig0)
'''

How to operate on a neighborhood or patch of surrounding pixels?

This question is for the Halide language.
Say for a particular (x, y), I want to operate on a KxK patch around (x, y). E.g. sum them, square them, etc., to get the obtain the new value for (x, y).
Most of the Halide examples I've found "hard-code" selecting the neighboring coordinates. Like in this example, and also the blur algorithm example on the home page:
Func blur_x, blur_y; Var x, y;
// hard codes selecting x-1:x+1 and y-1:y+1
blur_x(x, y) = (input(x-1, y) + input(x, y) + input(x+1, y))/3;
blur_y(x, y) = (blur_x(x, y-1) + blur_x(x, y) + blur_x(x, y+1))/3;
But let's say I want to paramertize the size of my KxK patch. How would I select and then operate on a neighborhood of arbitrary size around (x, y)?
Regarding your questions in the comments, I think what you need is a Func with 4 Vars: output(x, y, xi, yi)
x, y is the coordinate of the pixel in the center of each patch, which is effectively the ordinary coordinate of the pixel in an image. And xi, yi is the inner coordinate of the pixels within each patch.
output(x, y, xi, yi) = input(x + xi, y + yi)
In this way, you get a group of pixels that you can operate on.
Maybe this is an answer.
// First add the boundary condition.
Func clamped = BoundaryConditions::repeat_edge(input);
// Define a 5x5 box that starts at (-2, -2)
RDom r(-2, 5, -2, 5);
// Compute the 5x5 sum around each pixel.
Func local_sum;
local_sum(x, y) = 0; // Compute the sum as a 32-bit integer
local_sum(x, y) += clamped(x + r.x, y + r.y);

How to I change an n-by-n matrix to a point cloud matrix?

I have a 1265x1777 matrix with the intensity values of an image. I need to develop a point cloud file in MATLAB for the same. Just like a 3D scatter where x, y and z coordinates are stored in a variable; x, y should represent the pixel location; and z corresponds to the intensity of that pixel.
Edit: Updated according to OP's comment.
Assuming your 1265x1777 matrix is called 'img':
x = 1:size(img,2);
y = 1:size(img,1);
[X,Y] = meshgrid(x,y);
xyz_matrix = [X(:), Y(:), img(:)];

How to generate the stair step curve(outline) for any 2d shape(or curve)?

If I have the coordinates of the points on the outline of an arbitrary 2D shape, how can I find the coordinates of points composing the outline of a stair step curve, which best represents the original outline, but only use a set of known coordinates (xi, i=1,...,n and yi, i=1,...,m). For example the original triangle is represented by the thick solid blue line. it's different from the matlab stairs function, if my understanding is correct.
matlab code will be nice, but in other language is also ok, algorithm is most important.Thanks.
I'll start by defining a set of sample data based on your plot. Assuming that the pixel centers are aligned at integer values (the convention MATLAB follows) and that the lower left corner is at (0.5, 0.5), here's the data we get:
vx = [1.5; 9.7; 3.7; 1.5]; % X values of triangle vertices
vy = [8.3; 6.0; 1.7; 8.3]; % Y values of triangle vertices
x = 1:10; % X pixel center coordinates
y = 1:9; % Y pixel center coordinates
Note that the vertex coordinates are ordered starting at the top left corner of the triangle and proceeding clockwise, repeating the first vertex at the end to close the polygon.
Getting the mask (the easy part):
There is an easy way to compute the dark gray mask if you have the Image Processing Toolbox: use poly2mask:
mask = poly2mask(vx, vy, numel(y), numel(x));
The algorithm this function uses is discussed here. However, if you'd like to use a pure MATLAB approach that requires no special toolboxes, you can use inpolygon instead:
[cx, cy] = meshgrid(x, y); % Generate a grid of x and y values
mask = inpolygon(cx, cy, vx, vy);
In this case, a pixel is included in the mask as long as its center point lies within the polygon. In this particular example these two approaches yield the same resulting mask, but they won't always due to the differences in their criteria for deciding if a pixel is included or not.
Getting the outline coordinates:
It's a little more involved to get the coordinates of the mask outline, ordered appropriately around the perimeter. To accomplish this, we can represent the mask as a series of vertices and triangular facets (using the triangulation function), then compute the free boundary (i.e. edges that are only present on one triangular facet):
% Create raw triangulation data:
[cx, cy] = meshgrid(x, y);
xTri = bsxfun(#plus, [0; 1; 1; 0], cx(mask).');
yTri = bsxfun(#plus, [0; 0; 1; 1], cy(mask).');
V = [xTri(:) yTri(:)];
F = reshape(bsxfun(#plus, [1; 2; 3; 1; 3; 4], 0:4:(4*nnz(mask)-4)), 3, []).';
% Trim triangulation data:
[V, ~, Vindex] = unique(V, 'rows');
V = V-0.5;
F = Vindex(F);
% Create triangulation and find free edge coordinates:
TR = triangulation(F, V);
freeEdges = freeBoundary(TR).';
xOutline = V(freeEdges(1, [1:end 1]), 1); % Ordered edge x coordinates
yOutline = V(freeEdges(1, [1:end 1]), 2); % Ordered edge y coordinates
And we can plot this like so:
imagesc(x, y, mask);
axis equal
set(gca, 'XLim', [min(x)-0.5 max(x)+0.5], ...
'YLim', [min(y)-0.5 max(y)+0.5], ...
'XTick', x, 'YTick', y, 'YDir', 'normal');
colormap([0.9 0.9 0.9; 0.6 0.6 0.6]);
hold on;
plot(xOutline, yOutline, 'b', 'LineWidth', 2);
plot(xOutline(1), yOutline(1), 'go', 'LineWidth', 2);
plot(vx, vy, 'r', 'LineWidth', 2);
The outline coordinates in xOutline and yOutline are ordered starting from the green circle going counter-clockwise around the mask region.
Seems you need any line rasterization algorithm (that gives coordinate of integer grid points approximating line segment).
Consider Bresenham algortihm or DDA one.

Quaternion Rotation relative to world

Unity3D offers the following method:
Rotate(eulerAngles: Vector3, relativeTo: Space = Space.Self);
For example, this will rotate the object around it's local X axis:
transform.Rotate(Vector3(50,0,0) * Time.deltaTime, Space.Local);
If I first rotate 90 degrees around it's local y axis (which is up in unity) and then rotate it around the X axis relative to World, it will basically rotate around the local Z axis, ie:
//setup
transform.Rotate(Vector3(0, 90, 0));
//on update
transform.Rotate(Vector3(50,0,0) * Time.deltaTime, Space.World);
In my own implementation, using quaternions, I have the local rotation implemented, which was easy.
//rotate around local axis
currentRotation *= rotateQuat;
How would I go about implementing the relative to world behaviour using quaternions?
There's probably a way to do it in Unity without explicit calculations, but...
When using quaternions for rotation, it makes more sense to think in terms of a rotation (angle a) around a specific axis (unit vector u) rather than using Euler angles; the quaternion itself (actually a unit quaternion, or "versor") can be represented as a 4-vector (w, x, y, z), where w = cos(0.5*a) and (x, y, z) = (u_x, u_y, u_z) * sin(0.5*a) (meaning a = 2 * arccos(w) and u = (x, y, z) / sin(0.5*a) = (x, y, z) / sin(arccos(w)) ). Following from this, the "identity" quaternion (i.e. no rotation) is (1, 0, 0, 0), as cos(0) = 1 and sin(0) = 0, and very usefully, the inverse/conjugate of a quaternion, (w, -x, -y, -z), represents the opposite rotation (x, y, and z are technically imaginary components; you can also represent a quaternion as w+x*i+y*j+z*k). To apply a rotation to a point p in 3D space using a quaternion, you use p' = (w, x, y, z)*(0, p_x, p_y, p_z)*(w, -x, -y, -z), where the multiplication is performed as shown here: http://en.wikipedia.org/wiki/Quaternion#Ordered_list_form
Thus, performing a world-relative rotation with a quaternion given an already-existing rotation represented by a quaternion is relatively simple if you know what the angle and axis of rotation (in world space) are for the new rotation, as the main addition to the computation is to apply the conjugate of the existing quaternion to the axis of rotation for the new quaternion in order to represent that axis in local/object space; then you just create the quaternion for the new rotation and apply it to the existing one (I'm not sure how Unity orders quaternion composition, but normally if you apply q1 followed by q2 the composed quaternion would be q2*q1 [quaternion multiplication is non-commutative], so it should be something like resultQuat = newQuat * prevQuat;).

Resources