Ellipse Path
i am trying to move an object in ellipse path. but i don't know correct way and i think it need some of math and equation that i don't know until now
import SwiftUI
struct RotateObjectInEllipsePath: View {
let timer = Timer.publish(every: 0.01, on: .main, in: .common).autoconnect()
@State private var angle: Double = .zero
var body: some View {
VStack {
// circle shape
Circle()
.strokeBorder(Color.red, lineWidth: 2)
.frame(width: 250, height: 250)
.overlay(
Image(systemName: "arrow.down")
.offset(x: 250/2)
.rotationEffect(.degrees(angle))
)
//Spacer
Spacer()
.frame(height: 100)
// ellipse shape
Ellipse()
.strokeBorder(Color.red, lineWidth: 2)
.frame(width: 250, height: 150)
.overlay(
Image(systemName: "arrow.down")
.offset(x: 250/2)
.rotationEffect(.degrees(angle))
)
}// VStack
.animation(.default)
.onReceive(timer) { _ in
angle += 1
}
}
struct RotateObjectInEllipsePath_Previews: PreviewProvider {
static var previews: some View {
RotateObjectInEllipsePath()
}}
i found this code in community
x = x_center + Acos(2pi*t/T);
y = y_center + Bsin(2pi*t/T);
When A == B, the trajectory is a circumference
question from:https://stackoverflow.com/questions/65603101/how-to-move-an-object-in-ellipse-path-in-swiftui