前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【Android UI】Path 测量 PathMeasure ② ( PathMeasure API 简介 | nextContour 函数 | getPosTan 函数 ★ | 曲线切线处理 )

【Android UI】Path 测量 PathMeasure ② ( PathMeasure API 简介 | nextContour 函数 | getPosTan 函数 ★ | 曲线切线处理 )

作者头像
韩曙亮
发布2023-03-30 15:59:15
4450
发布2023-03-30 15:59:15
举报
文章被收录于专栏:韩曙亮的移动开发专栏

文章目录

一、PathMeasure API 简介


PathMeasure 官方文档 : https://developer.android.google.cn/reference/kotlin/android/graphics/PathMeasure

PathMeasure 是 Path 的一个 工具类 , 字面意思就是 Path 的测量工具类 ,

为该 PathMeasure 设置一个 Path 对象 , 则可以对 Path 的 路径 , 轨迹 进行测量 , 可以精确的计算出 Path 的运动轨迹 ,

PathMeasure 提供了 7 个函数用于实现相关功能 ;

1、nextContour 函数

nextContour 函数 作用是 跳转到下一个轮廓 ;

Path 是可以进行组合的 , 调用 Path 的 op 函数 , 可以将两个 Path 轮廓组合在一起 , 设置了组合以后 , 假如对其中的一个 Path 进行测量 , 调用 nextContour 函数 , 即可对另外一个 Path 轮廓进行测量 ;

两个 Path 没有先后顺序 ;

nextContour 函数原型 :

代码语言:javascript
复制
open fun nextContour(): Boolean

Move to the next contour in the path. 
Return true if one exists, or false if we're done with the path.

移动到路径中的下一个轮廓。
如果存在,则返回true;如果路径已完成,则返回false。

2、getPosTan 函数 ★

getPosTan 函数 作用是 获取指定长度位置的坐标点 以及该点对应切线的值 ;

getPosTan 函数原型 :

代码语言:javascript
复制
open fun getPosTan(
    distance: Float, 
    pos: FloatArray!, 
    tan: FloatArray!
): Boolean

Pins distance to 0 <= distance <= getLength(), 
and then computes the corresponding position and tangent. 

Returns false if there is no path, or a zero-length path was specified, 
in which case position and tangent are unchanged.

将距离固定到0<=距离<=getLength(),
然后计算相应的位置和切线。

如果没有路径或指定了零长度路径,则返回false,
在这种情况下,位置和切线不变。
  • distance: Float 参数 : 沿当前轮廓进行采样的距离 ;
代码语言:javascript
复制
The distance along the current contour to sample
  • pos: FloatArray! 参数 : 如果不为null,则返回采样位置(x==[0],y==[1]) ;
代码语言:javascript
复制
If not null, returns the sampled position (x==[0], y==[1])
  • tan: FloatArray! 参数 : 如果不为null,则返回采样的切线(x==[0],y==[1]);
代码语言:javascript
复制
If not null, returns the sampled tangent (x==[0], y==[1])
  • Boolean 返回值 : 如果没有与此度量值对象关联的路径,则为false ;
代码语言:javascript
复制
false if there was no path associated with this measure object

pos: FloatArray! 和 tan: FloatArray! 这两个数组 , 适用于接收返回值的 , 并不是用于参数传递 ;

只有曲线找切线才有意义 , 直线的切线直接就是 ( 0, 0 ) 坐标 ;

下图中 , 蓝色是 圆形 的曲线 , 红色点 是 曲线上的点 , 则 绿色点就是获取的 tan: FloatArray 参数值 , 该点是曲线的圆心 , 与曲线上的点连接 , 垂直与切线 ;

在这里插入图片描述
在这里插入图片描述
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-06-02,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 文章目录
  • 一、PathMeasure API 简介
    • 1、nextContour 函数
      • 2、getPosTan 函数 ★
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档