unit 模型的位置坐标转换到UI坐标

    /// <summary>
    /// 相机
    /// </summary>
    public Camera m_Camera;
        /// <summary>
    /// UI按钮
    /// </summary>
    public RectTransform UIBtn;
    void Update()
    {
            //坐标转换 世界转屏幕
            Vector2 screenPoint = RectTransformUtility.WorldToScreenPoint(m_Camera, transform.position);
            Vector2 localPoint;
            //坐标转换 屏幕转UI
            if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasTran, screenPoint, m_Camera, out localPoint))
            {
                UIBtn.anchoredPosition = localPoint;
            }
    }
       
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在C#中进行7参数坐标转换可以使用Proj.Net库,该库提供了许多常用的地图投影和坐标转换功能,包括基于七参数模型的大地坐标转换。以下是使用Proj.Net进行7参数坐标转换的示例: 1. 安装Proj.Net库 可以通过NuGet包管理器来安装Proj.Net库,或者在Visual Studio中的“工具”菜单中选择“NuGet包管理器”->“程序包管理器控制台”,执行以下命令安装Proj.Net库: ``` Install-Package ProjNet ``` 2. 创建CoordinateTransformation对象 使用Proj.Net进行坐标转换需要先创建一个CoordinateTransformation对象,该对象包含了换的源坐标系和目标坐标系。可以使用ProjNet.CoordinateSystems库中的CoordinateSystemFactory类来创建坐标系对象,然后使用ProjNet.CoordinateSystems.Transformations库中的CoordinateTransformationFactory类来创建CoordinateTransformation对象。例如,以下代码创建了一个CoordinateTransformation对象,用于从WGS84坐标换到Beijing 1954坐标系: ```csharp using ProjNet.CoordinateSystems; using ProjNet.CoordinateSystems.Transformations; using ProjNet.Converters.WellKnownText; // 创建WGS84坐标系 ICoordinateSystem wgs84 = CoordinateSystemFactory.CreateGeographicCoordinateSystem( "WGS 84", AngularUnit.Degrees, HorizontalDatum.WGS84, PrimeMeridian.Greenwich); // 创建Beijing 1954坐标系 ICoordinateSystem beijing54 = CoordinateSystemFactory.CreateProjectedCoordinateSystem( "Beijing 1954", "Beijing 1954 / Gauss-Kruger zone 18", "Gauss-Kruger", wgs84, LinearUnit.Metre, new AxisInfo("north", AxisOrientationEnum.North), new AxisInfo("east", AxisOrientationEnum.East), new PointF(75, 0.9996f), null, null, null); // 创建CoordinateTransformation对象 CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory(); CoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(wgs84, beijing54); ``` 3. 进行坐标转换 使用CoordinateTransformation对象的MathTransform属性可以获取换的数学模型,然后使用该模型的Transform方法进行坐标转换。例如,以下代码将WGS84坐标系下的经度为116.39745,纬度为39.90869的点换为Beijing 1954坐标系下的坐标: ```csharp double[] wgs84Coord = new double[] { 116.39745, 39.90869 }; double[] beijing54Coord = trans.MathTransform.Transform(wgs84Coord); ``` 在实际应用中,需要使用7个参数来配置CoordinateTransformation对象,这可以通过ProjNet.Converters.WellKnownText库中的WktOperations类来完成。例如,以下代码创建了一个包含7个参数的WKT字符串,然后使用WktOperations类的CreateFromWkt方法将其换为CoordinateTransformation对象: ```csharp string wkt = "PARAMETER[\"dx\", 23.47], PARAMETER[\"dy\", -53.04], PARAMETER[\"dz\", -19.51], PARAMETER[\"rx\", -0.000000029639432], PARAMETER[\"ry\", -0.000000061387052], PARAMETER[\"rz\", -0.000000022927735], PARAMETER[\"ds\", 0.000000000000000]"; ICoordinateTransformation trans = (ICoordinateTransformation)new CoordinateTransformationFactory().CreateFromWkt(wkt); ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值