Android Question Please guide me how to draw continuous curve passing through 2 points (CurveTo )

phongka

Member
muốn vẽ 1 đường cong đi qua 2 điểm gốc tọa độ (curveto) em đã search rất nhiều thông tin trên diễn đàn nhưng không được kết quả như mong muốn... và đây là kết quả của em.. nó rất tệ...vậy Tôi hy vọng sẽ giúp được..cảm ơn bạn

Ví dụ:
Sub Test_Vevoibrush(bc Là BitmapCreator)

    
    Dim g1 As Int = 20dip
    Dim g2 As Int = 30dip
    Dim p As BCPath
    p.Initialize(g1, 0).LineTo(bc.mWidth - g2 , 0)
    Hotro_PathCurveTo(p, bc.mWidth - g2 , 0, bc.mWidth, g2)
    p.LineTo (bc.mWidth, bc.mHeight)
    'P.
    
    bc.DrawPath(p, Colors.Red, True, 10dip)

kết thúc phụ

Sub Hotro_PathCurveTo (Path1 dưới dạng BCPath, tdX_1 dưới dạng float, tdY_1 dưới dạng float, TargetX dưới dạng float, TargetY dưới dạng float)
    'tdX_1, tdY_1: start point
    Dim LastPoint As InternalBCPathPointData = Path1.Points.Get(Path1.Points.Size - 1)
    Dim CurrentX As Float = LastPoint.X
    Dim Currenty As Float = LastPoint.Y
    Dim NumberOfSteps As Int = 15' <--- thay đổi khi cần thiết
    Dim dt As Float = 1 / NumberOfSteps
    Dim t As Float = dt
    Đối với i = 1 đến NumberOfSteps
        Dim tt1 Khi Float = (1 - t) * (1 - t)
        Dim tt2 As Float = 2 * (1 - t) * t
        Dim tt3 Như Phao = t*t
        Dim x As Float = tt1 * CurrentX + tt2 * tdX_1 + tt3 * TargetX
        Dim y As Float = tt1 * Hiện tại + tt2 * tdX_1 + tt3 * TargetY
        Đường dẫn1.LineTo(x, y)
        t = t + dt
    Kế tiếp
kết thúc phụ


[/MÃ SỐ]
 

Attachments

  • z4154445102320_481cd9bd110e6f5fbc07484ce83a26ac.jpg
    z4154445102320_481cd9bd110e6f5fbc07484ce83a26ac.jpg
    60.5 KB · Views: 64

klaus

Expert
Licensed User
Longtime User
This works :
B4X:
   p.Initialize(g1, 0).LineTo(bc.mWidth - g2 , 0)
   CurveTo(p, bc.mWidth - g2 / 2 , g3, bc.mWidth, 0)
   p.LineTo (bc.mWidth, bc.mHeight)
  
   bc.DrawPath(p, xui.Color_Red, True, 10dip)

CurveTo draws a parabola given by three points, these are the last point in the path and the two points given in CurveTo.
So, the last point in the path is bc.mWidth - g2, 0.
And in the CurveTo routine you must give the lowest point which is bc.mWidth - g2, g3.
And the end point which is bc.mWidth, 0.
You should use two variables, one for the parabola width and another one for the parabola height, g3 in the example above.

1677917192548.png
 
Upvote 1

emexes

Expert
Licensed User
I thought the optimal curve passing through two points was a straight line.

Three points can define a circle or arc, or a parabola if there are no duplicate x values.
 
Upvote 0
Top