untiy UI的坐标转为屏幕坐标

在某些情况下我们需要获取UI的屏幕坐标,但是目标UI有很多父物体,难以计算屏幕坐标,我们可以用UICameral来实现

首先要求画布改为 ScreenSpace-Camera模式,然后编写脚本

 UICamera.WorldToScreenPoint(m_transform.position);

UICamera就是你的UI相机 m_transform是你要获取坐标的UI的transform组件
需要注意的是,目标UI的锚点必须是一个点

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是将东北天坐标换为大地坐标的 MATLAB 代码: ```matlab function [lat,lon,h] = ned2lla(n,e,d,lat0,lon0,h0) % NED to LLA coordinate conversion % Input: % n,e,d - North, East, Down (meters) % lat0, lon0, h0 - Reference point in degrees and meters % Output: % lat,lon,h - Latitude, Longitude (degrees), Height (meters) % WGS84 ellipsoid parameters a = 6378137; f = 1/298.257223563; b = a*(1-f); % Convert reference point to ECEF [rx,ry,rz] = lla2ecef(lat0,lon0,h0); % Rotation matrix from NED to ECEF R = [-sin(lat0)*cos(lon0) -sin(lat0)*sin(lon0) cos(lat0); -sin(lon0) cos(lon0) 0; -cos(lat0)*cos(lon0) -cos(lat0)*sin(lon0) -sin(lat0)]; % Convert NED to ECEF p = [n;e;-d]; p_ecef = R*p + [rx;ry;rz]; % Convert ECEF to LLA [lat,lon,h] = ecef2lla(p_ecef(1),p_ecef(2),p_ecef(3)); end function [x,y,z] = lla2ecef(lat,lon,h) % Convert from geodetic coordinates to ECEF coordinates % Input: % lat,lon,h - Latitude and longitude in degrees, altitude in meters % Output: % x,y,z - ECEF coordinates in meters % WGS84 ellipsoid parameters a = 6378137; f = 1/298.257223563; b = a*(1-f); e2 = 1 - (b/a)^2; % Convert to radians lat = lat*pi/180; lon = lon*pi/180; % Radius of curvature in prime vertical N = a./sqrt(1-e2*sin(lat).^2); % ECEF coordinates x = (N+h).*cos(lat).*cos(lon); y = (N+h).*cos(lat).*sin(lon); z = (N.*(1-e2)+h).*sin(lat); end function [lat,lon,h] = ecef2lla(x,y,z) % Convert from ECEF coordinates to geodetic coordinates % Input: % x,y,z - ECEF coordinates in meters % Output: % lat,lon,h - Latitude and longitude in degrees, altitude in meters % WGS84 ellipsoid parameters a = 6378137; f = 1/298.257223563; b = a*(1-f); e2 = 1 - (b/a)^2; % Distance from z axis r = sqrt(x.^2 + y.^2); % Longitude lon = atan2(y,x); % Bowring's formula for initial estimate of latitude p = sqrt(x.^2 + y.^2)/a; lat = atan(z./(p.*(1-e2))); % Iterate until convergence for i=1:10 N = a./sqrt(1-e2*sin(lat).^2); h = r./cos(lat) - N; lat = atan(z./(p.*(1-e2*N./(N+h)))); end % Convert to degrees lat = lat*180/pi; lon = lon*180/pi; end ``` 其中,`n`,`e` 和 `d` 分别是东北天坐标系下的三个坐标值,`lat0`,`lon0` 和 `h0` 是参考点的大地坐标系下的纬度、经度和高度。函数的输出是大地坐标系下的纬度、经度和高度。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值