Sort list of coordinates - geometry

I have the following problem:
I have a list of all the x, y coordinates of a polygon's points.
I now need to sort them in such a way that I obtain the points in a
clockwise order.
Currently I have the 6 coordinates to draw a polygon but its not in order.
Does anyone know how to accomplish that?
Input coordinates :
Coordinate: 506.6609866568262, 673.970398950142
Coordinate: 505.34898334317376, 682.8179210498581
Coordinate: 502.0723751660178, 680.523615304454
Coordinate: 534.3026433431738, 682.736131049858
Coordinate: 535.6146466568263, 673.8886089501419
Coordinate: 538.8912548339822, 676.1829146955461
Output coordinates :
Coordinate: 506.6609866568262, 673.970398950142
Coordinate: 502.0723751660178, 680.523615304454
Coordinate: 505.34898334317376, 682.8179210498581
Coordinate: 534.3026433431738, 682.736131049858
Coordinate: 538.8912548339822, 676.1829146955461
Coordinate: 535.6146466568263, 673.8886089501419
Thanks in advance,

Use polar coordinates:
find an internal point to the polygon as a reference, say (c,d);
use atan2(x-c, y-d) for each vertex (x,y) of the polygon to get the polar angles from that internal point; then
sort by the angles you get.
If the polygon is convex, averaging the max and min values of x and likewise for y should get you an internal point. Otherwise, you have more work to do.

Related

tangent (y/x) gives values in the range of -180 to +180 degree. Is there a need to change the range?

I am calculating the spherical coordinates of the 3D geometry. I used below formula to find coordinats.
r = np.sqrt(x*x + y*y + z*z) # Radial distance
theta = np.arctan2(y,x)*180/ pi # Polar angle to degrees
phi = np.arccos(z/r)*180/ pi # Azimuth angle to degrees
I got the list of theta values like below.
theta = [-145.75, -164.54, -155.10, -124.70, 146.31, 109.80, 101.56, 77.20, 56.61, 40.76, 11.69, -24.15, -47.82, -72.65, -105.71, -131.19, -52.43, 30.96, 68.20, -145.75, -164.54, -155.10, -124.70, 146.31, 109.80, 101.56, 77.20, 56.61, 40.76, 11.69, -24.15, -47.82, -72.65, -105.71, -131.19, -52.43, 30.96, 68.20]
From these values, I can see that, these values are in between -180 to +180 degree. And also some angles are more than 180 degree and obtained values shows -145.75.
Is there any need to convert the range and values of theta?? How can I do this?
And I have the list of Azimuth angle (Phi) also. May I know that, if there is any need to convert the range of that also?
phi = [99.49, 101.02, 107.10, 121.000000000000, 131.29, 109.67, 101.94, 101.89, 100.22, 103.93, 107.79, 106.64, 102.41, 105.82, 105.95, 102.59, 120.08, 129.17, 109.43, 80.51, 78.98, 72.90, 59.0000000000000, 48.71, 70.33, 78.06, 78.11, 79.78, 76.07, 72.21, 73.36, 77.59, 74.18, 74.05, 77.41, 59.92, 50.83, 70.57]
What I want to do and what is a motive behind asking this question?
I want to project the nodes (coordinate) of geometry to the spherical surface which is created around an geometry. Therefore I am calculating angles of each coordinate available in geometry.
In spherical surface, I have created equal points. I will calculate angles for each points also. My aim is to project geometrical nodes into spherical surface and then I will calculate the number of nodes presented in the each part of spherical surface. Therefore in order to compare the angles of geometry and points of spherical surface, I want polar angles.

Geometry of a radial coordinate to Cartesian with bounding points

I need to find 4 points in Latitude/Longitude format surrounding a given center point and a resulting algorithm (if possible).
Known information:
Equal distances for each "bin" from center of point (Radar) outward.
Example = .54 nautical miles.
1 Degree beam width.
Center point of the "bin"
This image is in Polar coordinates (I think this is similar to Radial coordinates???):
I need to convert from Polar/Radial to Cartesian and I should be able to do that with this formula.
x = r × cos( θ )
y = r × sin( θ )
So now all I need to do is find the "bin" outline coordinates (4 corners) so I can draw a polygon in a Cartesian coordinate space.
I'm using Delphi/Pascal for coding, but I might be able to convert other languages if you have a sample algorithm.
Thanks for any suggestions or sample algorithms.
Regards,
Bryan
You need to convert everything to the same coordinate system and then impose the distance criteria as follows:
Convert your center point from geographic coordinates to polar coordinates to yield (rC, θC)
Convert your center point from polar to Cartesian coordinates using your equations yielding (xC, yC)
The corner points on the right side of the center points (xR, yR) satisfy the equation
(xR - xC)2 + (yR - yC)2 = D2
[rRcos(θC+0.5o) - xC]2 + [rRsin(θC+0.5o) - yC]2 = D2
where D=distance between the center point and corner points
Everything is known in the above equation except rR. This should yield a quadratic equation with two solutions which you can easily solve. Those are your two corner points on the right side.
Repeat step 3 with angle θC-0.5o to get the corner points on the left side.

Ellipse Volume withMonte Carlo Method

Sorry.I have a homework but I cannot do.I have to write code for between cube and ellipse'volume with Monte Marlo Method.Can you help me? Dimension for cube is 10 and radius for ellipse is 5 and height is 3.
Thank you
I wrote this codes for the intersection of a cylinder and a sphere but I cannot translate for ellipse and cube
%clear the workspace and command window
clc
clear
% find the volume of the intersection of a cylinder and a sphere
RunLength=10000; % run length
Count=0;
%initialize the empty arrays
px=[];
py=[];
pz=[];
qx=[];
qy=[];
qz=[];
d=0.2
%try 10000 points
for i=1:RunLength
x=2*rand()-1; %x coordinate random number between (-1,1)
y=2*rand()-1; %y coordinate random number between (-1,1)
z=2*rand()-1; %z coordinate random number between (-1,1)
if(x^2+y^2+z^2<=1); %if the point is in the big sphere (x^2+y^2+z^2<=1^2)
if (y^2+(z-(1-0.5)^2)>=(0.5)^2);
qx(end+1)=x; %add this point's x coordinate to the qx array
qy(end+1)=y; %add this point's y coordinate to the qy array
qz(end+1)=z; %add this point's z coordinate to the qz array
Count=Count+1; %increase the number of points in the shape by 1
end
else
px(end+1)=x; %add this point's x coordinate to the px array
py(end+1)=y; %add this point's y coordinate to the py array
pz(end+1)=z; %add this point's z coordinate to the pz array
end
end
%ratio is the number of points in the shape/total number of points
disp(8*Count/RunLength); %multiply the ratio with 8 and display
%use plot3 command because it is a 3D plot and use ‘ro’ for showing points as
%red circles in the plot
%use plot3 command because it is a 3D plot and use ‘ro’ for showing points as
red circles in the plot
plot3(qx,qy,qz,'ro');

Find size of inner rect of a circle

I have a circle, say radius of 10, and I can find the outer bounding rect easy enough since its width and height is equal to the radius, but what I need is the inner bounding rect. Does anyone know how to calculate the difference in size from the outer and inner bounding rectangles of a circle?
Here's an image to illustrate what I'm talking about. The red rectangle is the outer bounding box of the circle, which I know. The yellow rectangle is the inner bounding rectangle of the circle, which I need to find the difference in size from the outer rectangle.
My first guess to find the difference is to find one of the four points of the inner rectangle by finding that point along the circumference of the circle, each point being at a 45 degree offsets, and then just find the different from that point and the related point in the larger rect.
EDIT: Based off of the solution given by Steve B. I've come up with the algorithm to get what I want which is the following:
r*2 - sqrt(2)*r
If the radius is r, the outer rectangle size will be r*2.
The inner rectangle will have size equals to 2*sqrt(2*r).
So the diff will be equals to 2*(r-sqrt(2*r^2)).
You know the size of the radius and you have a triangle with a corner of 90 degrees with one point as the center of your circle and another two as two corners of your inner square.
Now if you know two sides of a triangle you can use Pythagoras:
x^2 = a^2 + b^2
= 2* r^2
So
x = sqrt(2 * r^2)
With r the radius of the circle, x the side of the square.
It's simple geometry: Outer rectangle has length of edge equal to 2*R, inner - diagonal equal to 2*R. So the edge of inner rectangle is equal to sqrt(2)*R. The ratio of edges of outer rectangle divided by inner is obviously sqrt(2).

Convert 3D(x,y,z) to 2D(x,y) (orthogonal) along its direction

I have gone through all available study resources in the internet as much as possible, which are in form of simple equations, vectors or trigonometric equations.
I couldn't find the way of doing following thing:
Assuming Y is up in a 3D world.
I need to draw two 2D trajectories orthogonally (not the projections) for a 3D trajectory, say XY-plane for side view of the trajectory w.r.t. the trajectory itself and XZ-plane for top view for the same.
I have all the 3D points of the 3D trajectory, initial velocity, both the angles can be calculated by vector mathematics.
How should I proceed further?
refer:
Below a curve in different angles, which can loose its significance if projected along XY-plane. All I want is to convert the red curve along itself, the green curve along green curve and so on. and further how would I map side view to a plane. Top view is comparatively easy and done just by taking X and Z ordinates of each points.
I mean this the requirement. :)
I don't think I understand the question, but I'll answer my interpretation anyway.
You have a 3D trajectory described by a sequence of points p0, ..., pN. We are given an angle v for a plane P parallel to the Y-axis, and wish to compute the 2D coordinates (di, hi) of the points pi projected onto that plane, where hi is the height coordinate in the direction Y and di is the distance coordinate in the direction v. Assume p0 = (0, 0, 0) or else subtract p0 from all vectors.
Let pi = (xi, yi, zi). The height coordinate is hi = yi. Assume the angle v is given relative to the Z-axis. The vector for the direction v is then r = (sin(v), 0, cos(v)), and the distance coordinates becomes di = dot(pi, r).

Resources