美文网首页
Android--PathMeasure基本用法

Android--PathMeasure基本用法

作者: aruba | 来源:发表于2020-02-04 16:38 被阅读0次

    PathMeasure是一个用来测量Path的类

    构造方法
    //创建一个空的PathMeasure
    public PathMeasure()
    
    //创建 PathMeasure 并关联一个指定的Path(Path需要已经创建完成)。
    public PathMeasure(Path path, boolean forceClosed)
    
    其中参数forceClosed表示是否考虑path起始点,一般用false,不考虑起始点

    其他api
    • 关联一个Path,和第二个构造方法用法相同
    public void setPath(Path path, boolean forceClosed)
    
    • path是否闭合
    public boolean isClosed()
    
    • 获取Path的长度
    public float getLength()
    
    • 跳转到下一个轮廓
    public boolean nextContour()
    
    • 截取片段
      startD:开始位置
      stopD:结束位置
      dst:存放截取片段的path(注意是追加进目标path,而不是覆盖)
      startWithMoveTo:为false将会使用dst的末尾点(如果dst不是空的话)连接到截取片段的第一条直线的末尾点(第一条直线和第二条直线的拐点),总之为false挺蛋疼的,一般使用true
    public boolean getSegment(float startD, float stopD, Path dst, boolean startWithMoveTo)
    
    • 获取指定长度的位置坐标及该点切线值tangle
      distance:指定长度的位置
      pos[]:存放指定位置的坐标
      tan[]:正切值,其中tan[0]是邻边边长,tan[1]是对边边长,可以利用Math中 atan2 方法:根据正切数值计算出该角度的大小,得到的单位是弧度,再根据公式:弧度=角度/180 * π 可以得到角度
    public boolean getPosTan(float distance, float pos[], float tan[])
    
    • 获取指定长度的位置坐标及该点Matrix(矩阵)
      distance:指定长度的位置
      matrix:会根据 flags 的设置而存入不同的内容
      flags:
      ------ POSITION_MATRIX_FLAG(位置)
      ------ ANGENT_MATRIX_FLAG(正切)
    public boolean getMatrix(float distance, Matrix matrix, int flags)
    

    相关文章

      网友评论

          本文标题:Android--PathMeasure基本用法

          本文链接:https://www.haomeiwen.com/subject/vngrxhtx.html