Is it posssible to find an x/y coordinate without Angles? i need this for a target locator in a Scratch Program - triangulation

My scratch project:https://scratch.mit.edu/projects/657133771
i need a triangulation/trilateralation equation for a target locator. otherwise the tank is just stupid.

Try using the Distance Formula (Pythagorean Theorem) to calculate the distance between points. Simply use:
distance = sqrt( (x2-x1)^2 + (y2-y1)^2 )

Make the x and y change at the same time. It will give an angle effect, and your sprite does not have to turn. Not exactly a formula, but if you match up the x and y changes in the right way, you get different angles.

Related

Convert coordinate from one world coordinate system to object coordinate system

I am more interested in the mathematics behind this problem, but am using matlab to try and solve this problem. I have an object, positioned using the world coordinate system at (Wx, Wy, Wz)
I would like to calculate the coordinates of this point using the object coordinate system (Ox, Oy, Oz)
To do this, I first need to calculate the axes of the object coordinate system.
Step 1 is to find the Normal (Nx, Ny, Nz)
(assuming that this is not the world z-axis). My object has a yaw, pitch and roll angle applied so I need to find my normal relative to this.
To do this I use a rotational matrix and perform the operations in the order stated above.
Step 2 is to calculate the arbitrary axes.
If abs(Nx < 1/64) and abs(Ny < 1/64)
(Axx, Axy, Axz) = cross product of world y-axis (0,1,0) and the Normal
else
(Axx, Axy, Axz) = cross product of world z-axis (0,0,1) and the Normal
(Ayx, Ayy, Ayz) = cross product of N and Ax
I then scale my arbitrary axes by dividing by the sqrt of the sum of the squares.
Step 3 - Transform the coordinate
To transform the coordinate you point multiply the initial coordinate by each of the axes.
Ox = Wx * Axx + Wy * Axy + Wz * Axz
Oy = Wx * Ayx + Wy * Ayy + Wz * Ayz
Oz = Wx * Nx + Wy * Ny + Wz * Nz
DXF for autocad takes the object coordinates, the Normal vector and a rotation about the normal vector.
This appears to be working reasonable well at positioning the coordinate, but with some issues:
When I use the method above, I find that sometimes my objects are rotated 180 degrees. Digging into this, sometimes the Arbitrary x-axis is negative, sometimes it is positive. This may account for some objects being rotated, but Autocad does not actually reference this Ax vector. It calculates it. This means that I may have to correct this with a rotation about the normal, but I do not what it to always apply (I cannot simply look for a negative value and rotate if negative, as sometimes the object is required to be placed in this direction).I do not know how to overcome this.
If I apply a roll angle to the object and work through this process, the roll angle is not applied correctly. Instead this appears to translate this angle as an Yaw and Site change, but not actually the intended rotation. I cannot see what I have done using the above formula.

Best way to find the top most left coordinate point in set of Cartesian coordinates?

I have a set of cartesian coordinates. What is the best way to find the top most left coordinate?
My approach is to find max Y and then corresponding lowest X coordinate. (Since there could be multiple points with same Ymax). This works fine but wonders if there are other cute methods?
If your x and y coordinates are not sorted, then you have to check all the input coordinates - at first your y values (for topmost, the higher the better) and then all corresponding x values for such y, but now you look for minimal x.

Character Jump Arc? Alter the Y axis during Vector3.MoveTowards?

I'm trying to make a character jump between two points. The two points are varying distances apart, and at different heights.
I have the character moving from point to point using Vector3.MoveTowards in a IEnumerator. But how can I make modify the Y axis so that the character moves in a curved path to appear as if jumping?
The character needs to land exactly at each point, so I cannot use physics.
Thanks! :-)
Image Example
Extra bonus points if you can adjust where you want the peak of the jump to occur (so the curve isn't perfectly circular, but more like an arc) E.g. so that the peak of the jump is closer to destination.
Looking at your given image, I would suggest using a projectile motion's equation to calculate the path between the source and destination in a given time with a given start velocity(Vo) and given angle (theta).
In case you are not familiar with projectile equation, have a look at here:
https://en.wikipedia.org/wiki/Projectile_motion
In the Displacement section you'll find 2 equations like this:
x = Vo * T * cos(theta)
y = Vo * T * sin(theta) - 0.5 * g * pow(T,2)
So, in Update function don't move the object directly towards the target, rather take temporary targets along the projectile motion, which you can calculate using the above two equations. You can then use,
Vector3.MoveTowards(curPosition,new Vector3(x,y,0),step);
Considering, the z value is 0.

Arrange the vertices of a 3D convex polygonal plane in counter clockwise direction in MATLAB

I have a convex polygon in 3D. For simplicity, let it be a square with vertices, (0,0,0),(1,1,0),(1,1,1),(0,0,1).. I need to arrange these vertices in counter clockwise order. I found a solution here. It is suggested to determine the angle at the center of the polygon and sort them. I am not clear how is that going to work. Does anyone have a solution? I need a solution which is robust and even works when the vertices get very close.
A sample MATLAB code would be much appreciated!
This is actually quite a tedious problem so instead of actually doing it I am just going to explain how I would do it. First find the equation of the plane (you only need to use 3 points for this) and then find your rotation matrix. Then find your vectors in your new rotated space. After that is all said and done find which quadrant your point is in and if n > 1 in a particular quadrant then you must find the angle of each point (theta = arctan(y/x)). Then simply sort each quadrant by their angle (arguably you can just do separation by pi instead of quadrants (sort the points into when the y-component (post-rotation) is greater than zero).
Sorry I don't have time to actually test this but give it a go and feel free to post your code and I can help debug it if you like.
Luckily you have a convex polygon, so you can use the angle trick: find a point in the interior (e.g., find the midpoint of two non-adjacent points), and draw vectors to all the vertices. Choose one vector as a base, calculate the angles to the other vectors and order them. You can calculate the angles using the dot product: A · B = A B cos θ = |A||B| cos θ.
Below are the steps I followed.
The 3D planar polygon can be rotated to 2D plane using the known formulas. Use the one under the section Rotation matrix from axis and angle.
Then as indicated by #Glenn, an internal points needs to be calculated to find the angles. I take that internal point as the mean of the vertex locations.
Using the x-axis as the reference axis, the angle, on a 0 to 2pi scale, for each vertex can be calculated using atan2 function as explained here.
The non-negative angle measured counterclockwise from vector a to vector b, in the range [0,2pi], if a = [x1,y1] and b = [x2,y2], is given by:
angle = mod(atan2(y2-y1,x2-x1),2*pi);
Finally, sort the angles, [~,XI] = sort(angle);.
It's a long time since I used this, so I might be wrong, but I believe the command convhull does what you need - it returns the convex hull of a set of points (which, since you say your points are a convex set, should be the set of points themselves), arranged in counter-clockwise order.
Note that MathWorks recently delivered a new class DelaunayTri which is intended to superseded the functionality of convhull and other older computational geometry stuff. I believe it's more accurate, especially when the points get very close together. However I haven't tried it.
Hope that helps!
So here's another answer if you want to use convhull. Easily project your polygon into an axes plane by setting one coordinate zero. For example, in (0,0,0),(1,1,0),(1,1,1),(0,0,1) set y=0 to get (0,0),(1,0),(1,1),(0,1). Now your problem is 2D.
You might have to do some work to pick the right coordinate if your polygon's plane is orthogonal to some axis, if it is, pick that axis. The criterion is to make sure that your projected points don't end up on a line.

Dividing a geographic region

I have a certain geographic region defined by the bottom left and top right coordinates. How can I divide this region into areas of 20x20km. I mean in practial the shape of the earth is not flat it's round. The bounding box is just an approximation. It's not even rectangular in actual sense. It's just an assumption. Lets say the bottomleft coordinate is given by x1,y1 and the topright coordinate is given by x2,y2, the length of x1 to x2 at y1 is different than that of the length between x1 to x2 at y2. How can I overcome this issue
Actually, I have to create a spatial meshgrid for this region using matlab's meshgrid function. So that the grids are of area 20x20km.
meshgrid(x1:deltaY:x2,y1:deltaX:y2)
As you can see I can have only one deltaX and one deltaY. I want to choose deltaX and deltaY such that the increments create grid of size 20x20km. However this deltaX and deltaY are supposed to vary based upon the location. Any suggestions?
I mean lets say deltaX=del1. Then distance between points (x1,y1) to (x1,y1+del1) is 20km. BUt when I measure the distance between points (x2,y1) to (x2, y1_del1) the distance is < 20km. The meshgrid function above does creates mesh. But the distances are not consistent. Any ideas how to overcome this issue?
Bear in mind that 20km on the surface of the earth is a REALLY short distance, about .01 radians - so the area you're looking at would be approximated as flat for anything non-scientific. Assuming it is scientific...
To get something other than monotonic steps in meshgrid you should create a function which takes as its input your desired (x,y) and maps it relative to (x_0,y_0) and (x_max,y_max) in your units of choice. Here's an inline function demonstrating the idea of using a function for meshgrid steps
step=inline('log10(x)');
[x,y]=meshgrid(step(1:10),step(1:10));
image(255*x.*y)
colormap(gray(255))
So how do you determine what the function should be? That's hard for us to answer exactly without a little more information about what your data set looks like, how you're interacting with it, and what your accuracy requirements are. If you have access to the actual location at every point, you should vary one dimension at a time (if your data grid is aligned with your latitude grid, for example) and use a curve fit with model selection techniques (akaike/bayes criterion) to find the best function for your data.