貝塞爾曲線的應用

2021-07-16 10:18:50 字數 2347 閱讀 9932

本文參考了

demo的github位址

**就重寫乙個view而已 **如下:

** * created by abner on 2016/8/6.

*/ public class bubbleview extends view

public bubbleview(context context, attributeset attrs)

public bubbleview(context context, attributeset attrs, int defstyleattr)

//初始化

private void init()

@override

protected void ondraw(canvas canvas)

canvas.drawcircle(movex, movey, radius, paint);

}

}

@override

public boolean ontouchevent(motionevent event) else if (event.getaction() == motionevent.action_move) else if (event.getaction() == motionevent.action_up)

return true;

}

}

關鍵內容:

所以我們要畫2條二介的曲線來達到這種效果 就必須有6個點

因為貝塞爾的quadto(控制點x,控制點y,最後的位置 x ,最後的位置 y);

所以要 2個起點 2個終點 和2個控制點 但2個控制點是一樣的

控制點:

anchorx = (movex + startx) / 2;

anchory = (movey + starty) / 2;

這個是控制點 由 移動的位置加開始的位置/2 得到的就是2點中間的那個點 自己計算下就知道了

2個起點 和2個終點要怎麼計算呢

這是計算4個點的**

float offsetx = (float) (radius * math.sin(math.atan((movey - starty) / (movex - startx))));

float offsety = (float) (radius * math.cos(math.atan((movey - starty) / (movex - startx))));

float distance = (float) math.sqrt(math.pow(movey - starty, 2) + math.pow(movex - startx, 2));

radius2 = -distance / 15 + 50;

float offsetx2 = (float) (radius2 * math.sin(math.atan((movey - starty) / (movex - startx))));

float offsety2 = (float) (radius2 * math.cos(math.atan((movey - starty) / (movex - startx))));

float x1 = startx - offsetx2;

float y1 = starty + offsety2;

float x2 = movex - offsetx;

float y2 = movey + offsety;

float x3 = movex + offsetx;

float y3 = movey - offsety;

float x4 = startx + offsetx2;

float y4 = starty - offsety2;

這裡有2個radius 是用來實現拉伸時原先那個圓的大小會改變 這個不是我們要講的重點 可以忽略

然後接下來就利用這幾個點來畫曲線了

canvas.drawcircle(startx, starty, radius2, paint);

path.reset();

path.moveto(x1, y1);

path.quadto(anchorx, anchory, x2, y2);

path.lineto(x3, y3);

path.quadto(anchorx, anchory, x4, y4);

path.lineto(x1, y1);

canvas.drawpath(path, paint);

貝塞爾曲線

1.概述 貝塞爾曲線 b zier curve 又稱 貝茲曲線或貝濟埃曲線,是應用於二維圖形應用程式的數學曲線。一般的向量圖形 軟體通過它來精確畫出曲線,貝茲曲線由 線段與節點組成,節點是可拖動的支點,線段像可伸縮的皮筋,我們在繪圖工具上看到的鋼筆工具就是來做這種向量曲線的。貝塞爾曲線是計算機圖形學...

貝塞爾曲線

由於工作需要,最近在研究乙個類似qq訊息劃掉的效果 很多強迫症患者童鞋對這個簡直是愛不釋手,當然這個也包括我自己 貝塞爾曲線就是這樣的一條曲線,它是依據四個位置任意的點座標繪製出的一條 光滑曲線 在歷史上,研究貝塞爾曲線的人最初是按照已知曲線 引數方程 來確定四個點的思路設計出這種向量曲線繪製法。貝...

貝塞爾曲線

貝塞爾曲線在android中運用廣泛,可以用來繪製各類複雜曲線,因為貝塞爾曲線只需要指定控制點,就能繪製出特定的曲線。其次是做點和點的平滑過渡。為什麼可以做到如上兩點,看下面的講解 首先來說,貝塞爾曲線有階的概念,這個階可以理解為控制點,一階的控制點只有兩個。如上是一階的方程,其中t取值為0到1,可...