B4J Tutorial Trace of a point on a rolling wheel

1.png
 

Attachments

  • b4jRotatingWheel.zip
    2.2 KB · Views: 11

Daestrum

Expert
Licensed User
Longtime User
I think there is something odd in the image. After one rotation 360deg , the point will be pi * diameter to the right of original start.Therefore the paths shown (level with centre of circle horizontally) cannot overlap. Only if point radius is larger than circle radius can this happen.

(of course I could be wrong)
Edit: Its where you move wheel 1 unit but rotate by 0.1 degrees

try
B4X:
Sub Timer1_tick
    WheelAngle = (WheelAngle + 0.1)
 
     ' Move the wheel to the right based on the arc length

      WheelCenterX = WheelCenterX + (WheelRadius * 0.1) ' <<<<------ move wheel this amount.
 
  ' Calculate the new position of the point on the wheel
    PointX = WheelCenterX + WheelRadius * Cos(WheelAngle)
    PointY = WheelCenterY + WheelRadius * Sin(WheelAngle)



    ' Add the new position of the point to the trace path
    TracePath.Add(Array As Float(PointX, PointY))

    ' Redraw the canvas
    Canvas1.ClearRect(0, 0, Canvas1.Width, Canvas1.Height)
    DrawWheel
End Sub
 
Last edited:
Top