是否有将距离矩阵转换为一组坐标的包?我已经完成了以下问题.我希望有一个这方面的包.
我已经考虑过Sammons Projection,但据我所知,它是一个优化器,可以为您提供最佳解决方案.我认为应该有一个算法来获得一个独特的解决方案.
因此,我正在编写一个函数allCoords
,该函数返回宽度w
和高度h
两者的网格中每个可能坐标的列表,width
并且height
必须是非负整数才能返回合理的结果。
示例:allCoords 3 2
应该返回[(0,0),(0,1),(0,2),(1,0),(1,1),(1,2)]
到目前为止,这就是我所拥有的,但我什至不知道如何开始编写函数
type GridCoord = (Int, Int)
allCoords :: Int -> Int -> [GridCoord]
Run Code Online (Sandbox Code Playgroud) 我一直在寻找一种解决方案,将我所拥有的笛卡尔坐标(lat,long)转换为极坐标,以便于我想要运行的模拟,但是我没有在这里找到任何问题或答案. R.有很多选项,包括Matlab中的内置函数cart2pol,但我的所有数据都在R中,我想继续在这个框架中工作.
题:
我有来自标记数据的lat/long坐标,我想将它们转换为极坐标(意思是跳跃大小和角度:http://en.wikipedia.org/wiki/Polar_coordinate_system),这样我就可以随机播放或引导它们(没有决定哪个)约1000次,并计算每个模拟轨道从起点的直线距离.我有一个真正的轨道,我有兴趣通过模拟具有相同跳跃大小和转向角度的1,000个随机轨道来确定这种动物是否表现出场地亲和力,但是在完全不同的顺序和组合中.因此,我需要距离原点1000个直线距离来创建距离分布,然后将其与我的真实数据集的直线距离进行比较.
我很自在地进行自举,但是我在第一步停留,即将我的笛卡尔纬度/长坐标转换为极坐标(跳跃大小和转弯角度).我知道在Matlab等其他程序中有内置函数可以做到这一点,但我找不到任何方法在R中做到这一点.我可以手动在for循环中手动完成,但是如果有一个包出来的话有更简单的方法,我更喜欢这样做.
理想情况下,我想将数据转换为极坐标,运行模拟,然后为每个随机轨道输出一个终点作为笛卡尔坐标,lat/long,这样我就可以计算出行的直线距离.
我没有发布任何样本数据,因为它只是一个lat和long坐标的两列数据框.
感谢您的任何帮助,您可以提供!如果在本网站的某个地方或我错过的其他地方有一个简单的解释,请指出我的方向!我找不到任何东西.
干杯
simulation r coordinates polar-coordinates cartesian-coordinates
我正在研究空间分析问题,该工作流程的一部分是计算连接线段之间的角度.
每个线段仅由两个点组成,每个点都有一对XY坐标(笛卡尔坐标).这是GeoGebra的图像.我总是对在0到180范围内获得正角度感兴趣.但是,根据输入线段中顶点的顺序,我得到所有类型的角度.
我使用的输入数据以坐标元组的形式提供.根据顶点创建顺序,每个线段的最后/结束点可以不同.以下是Python代码中的一些案例.我得到它们的线段的顺序是随机的,但在元组的元组中,第一个元素是起点,第二个元素是终点.DE
线段,例如,本来((1,1.5),(2,2))
和(1,1.5)
为起点,因为它在坐标元组第一的位置.
但是,我需要确保我会得到的相同的角度DE,DF
,并ED,DF
依此类推.
vertexType = "same start point; order 1"
#X, Y X Y coords
lineA = ((1,1.5),(2,2)) #DE
lineB = ((1,1.5),(2.5,0.5)) #DF
calcAngle(lineA, lineB,vertexType)
#flip lines order
vertexType = "same start point; order 2"
lineB = ((1,1.5),(2,2)) #DE
lineA = ((1,1.5),(2.5,0.5)) #DF
calcAngle(lineA, lineB,vertexType)
vertexType = "same end point; order 1"
lineA = ((2,2),(1,1.5)) #ED
lineB = ((2.5,0.5),(1,1.5)) #FE
calcAngle(lineA, lineB,vertexType)
#flip lines order
vertexType = …
Run Code Online (Sandbox Code Playgroud) 我下载了天气数据,它有经度(十进制)、纬度(十进制)和海拔(米)值。没有有关所使用的坐标系的信息。我如何将其转换为笛卡尔坐标?我的尝试如下。但是,我的问题是找到正确的公式
def cartesian(self,longitude,latitude, elevation):
R = 6378137.0 + elevation # relative to centre of the earth
X = R * math.cos(longitude) * math.sin(latitude)
Y = R * math.sin(longitude) * math.sin(latitude)
Z = R * math.cos(latitude)
def cartesian3(self,longitude,latitude, elevation):
X = longitude * 60 * 1852 * math.cos(latitude)
Y = latitude * 60 * 1852
Z = elevation
return X,Y,Z
Run Code Online (Sandbox Code Playgroud)
Daphna Shezaf的回答使用了不同的公式。但是,它不使用高程。如果有人能消除我的困惑,我将不胜感激,是否应该使用海拔来从长/纬度转换?正确的公式是什么?我尝试使用特定的经度、纬度、海拔来比较我在该网站上的代码的结果。我上面的两种方法的结果与从网站获得的结果相差甚远
我想分享我的问题的解决方案。我已经在Python中实现了Matlab中的lla2ecef函数。它允许将弧度经度、纬度和海拔(高度以米为单位)转换为笛卡尔坐标。我只需要将纬度和经度转换为弧度,前提是它们是十进制的:
latitude = (lat * math.pi) / 180 #latitude in radian, and lat …
Run Code Online (Sandbox Code Playgroud) 我正在尝试将以下资源调整到这个问题:
https://matplotlib.org/gallery/pie_and_polar_charts/polar_scatter.html
我似乎无法获得坐标将树状图形状转移到极坐标.
有谁知道如何做到这一点?我知道networkx中有一个实现,但是需要构建一个图形,然后使用pygraphviz后端来获取位置.
有没有办法将树状图笛卡尔坐标转换为极坐标matplotlib
和numpy
?
import requests
from ast import literal_eval
import matplotlib.pyplot as plt
import numpy as np
def read_url(url):
r = requests.get(url)
return r.text
def cartesian_to_polar(x, y):
rho = np.sqrt(x**2 + y**2)
phi = np.arctan2(y, x)
return(rho, phi)
def plot_dendrogram(icoord,dcoord,figsize, polar=False):
if polar:
icoord, dcoord = cartesian_to_polar(icoord, dcoord)
with plt.style.context("seaborn-white"):
fig = plt.figure(figsize=figsize)
ax = fig.add_subplot(111, polar=polar)
for xs, ys in zip(icoord, dcoord):
ax.plot(xs,ys, color="black")
ax.set_title(f"Polar= {polar}", fontsize=15)
# Load the dendrogram data …
Run Code Online (Sandbox Code Playgroud) python plot dendrogram polar-coordinates cartesian-coordinates
我正在尝试编写两个函数来将笛卡尔坐标转换为球坐标,反之亦然。以下是我用于转换的方程式(也可以在此维基百科页面上找到):
和
这是我的spherical_to_cartesian
功能:
def spherical_to_cartesian(theta, phi):
x = math.cos(phi) * math.sin(theta)
y = math.sin(phi) * math.sin(theta)
z = math.cos(theta)
return x, y, z
Run Code Online (Sandbox Code Playgroud)
这是我的cartesian_to_spherical
功能:
def cartesian_to_spherical(x, y, z):
theta = math.atan2(math.sqrt(x ** 2 + y ** 2), z)
phi = math.atan2(y, x) if x >= 0 else math.atan2(y, x) + math.pi
return theta, phi
Run Code Online (Sandbox Code Playgroud)
并且,这是驱动程序代码:
>>> t, p = 27.500, 7.500
>>> x, y, z = spherical_to_cartesian(t, p)
>>> print(f"Cartesian coordinates:\tx={x}\ty={y}\tz={z}")
Cartesian coordinates: x=0.24238129061573832 …
Run Code Online (Sandbox Code Playgroud) python geometry polar-coordinates cartesian-coordinates spherical-coordinate
我想知道从Lat,Lon,Alt值到3D系统的转变,如ECEF(以地球为中心).
这可以通过以下方式实现(https://gist.github.com/1536054):
/*
* WGS84 ellipsoid constants Radius
*/
private static final double a = 6378137;
/*
* eccentricity
*/
private static final double e = 8.1819190842622e-2;
private static final double asq = Math.pow(a, 2);
private static final double esq = Math.pow(e, 2);
void convert(latitude,longitude,altitude){
double lat = Math.toRadians(latitude);
double lon = Math.toRadians(longitude);
double alt = altitude;
double N = a / Math.sqrt(1 - esq * Math.pow(Math.sin(lat), 2));
x = (N + alt) * Math.cos(lat) * Math.cos(lon);
y …
Run Code Online (Sandbox Code Playgroud) 网格http://i44.tinypic.com/1qo5mp.png
(角落中的小点是节点,红点是被跟踪的人)
坐标:
Node X Y Position
1 0 0 Top left
2 450 0 Top right
3 0 450 Bottom left
4 450 450 Bottom right
Person X Y
Red dot 84 68
Run Code Online (Sandbox Code Playgroud)
获得信号强度的方法:
(只需要相对于其他节点的信号强度,它似乎达到了.或者我错了吗?)
public int GetSignalStrength(OvalShape node)
{
int xd = node.Left - this.person.Left;
int yd = node.Top - this.person.Top;
var signalStrength = Math.Sqrt((xd * xd) + (yd * yd));
return Convert.ToInt32(-signalStrength);
}
Run Code Online (Sandbox Code Playgroud)
信号强度:
Node Signal Strength
1 -108
2 -372
3 -391
4 -529
Run Code Online (Sandbox Code Playgroud)
获取人的坐标的方法:
(s1,s2,s3,s4是上面的信号强度) …
python ×4
geometry ×2
r ×2
angle ×1
atan2 ×1
c# ×1
coordinates ×1
dendrogram ×1
gps ×1
haskell ×1
javascript ×1
math ×1
plot ×1
python-2.7 ×1
simulation ×1
trigonometry ×1