Share
Embed
【Sansan×ヤプリ×ディップ 3社合同モバイル勉強会 第2回】チ。-Chart3Dの挙動について-
Cychow
June 20, 2025
Transcript
18 slides
-
ٿͷيಓํఔࣜͷಋೖํ๏ έϓϥʔͷୈҰ๏ଇʮɺଠཅΛͭͷযͱ͢ΔପԁيಓΛඳ͘ʯ͔Βɺ r(θ) = a(1 − e2) 1 + e
cos θ x = r(θ)cos θ y = r(θ)sin θ S В Y Z Y Z ͱ͍ͬͨɺۃ࠲ඪͱަ࠲ඪͷ͕ؔࣜಋ͖ग़ͤΔͨΊɺ x(θ) = a(1 − e2)cos θ 1 + e cos θ y(θ) = a(1 − e2)sin θ 1 + e cos θ ͱ͍͏ͷيಓํఔ͕ࣜಘΒΕΔɻ a: ପԁͷܘ e: ৺ -
import SwiftUI import Charts struct OrbitData: Identifiable { let id
= UUID() let angle: Double // 0ʙ360 let x: Double let y: Double } struct PlanetsSimulationView: View { @State private var earthAngle: Double = 0 private let timer = Timer.publish(every: 0.02, on: .main, in: .common).autoconnect() // 360°ͷٿͷيಓσʔλΛੜ private let earthOrbit: [OrbitData] = { let a = 100.0 let e = 0.0167 return (0..<360).map { angle in let rad = Double(angle) * Double.pi / 180 let r = a * (1 - e * e) / (1 + e * cos(rad)) let earthX = r * cos(rad) let earthY = r * sin(rad) return OrbitData(angle: Double(angle), x: earthX, y: earthY) } -
var body: some View { Chart { // ଠཅΛϓϩοτ PointMark(
x: .value("X", -100.0 * 0.0167), y: .value("Y", 0.0) ) .foregroundStyle(.orange) // ٿͷيಓ ForEach(earthOrbit) { data in PointMark( x: .value("X", data.x), y: .value("Y", data.y) ) .foregroundStyle(.cyan) } // ٿΛݱࡏͷearthAngleҐஔʹϓϩοτ let earthA = 100.0 let earthE = 0.0167 let earthRad = earthAngle * Double.pi / 180 let earthR = earthA * (1 - earthE * earthE) / (1 + earthE * cos(earthRad)) let earthX = cos(earthRad) * earthR let earthY = sin(earthRad) * earthR PointMark( x: .value("X", earthX), y: .value("Y", earthY) ) -
.foregroundStyle(.cyan) } // ٿΛݱࡏͷearthAngleҐஔʹϓϩοτ let earthA = 100.0 let earthE
= 0.0167 let earthRad = earthAngle * Double.pi / 180 let earthR = earthA * (1 - earthE * earthE) / (1 + earthE * cos(earthRad)) let earthX = cos(earthRad) * earthR let earthY = sin(earthRad) * earthR PointMark( x: .value("X", earthX), y: .value("Y", earthY) ) .foregroundStyle(.cyan) } .onReceive(timer) { _ in withAnimation(.linear(duration: 0.02)) { earthAngle = (earthAngle + 1).truncatingRemainder(dividingBy: 360) } } } } -
import SwiftUI import Charts struct OrbitData: Identifiable { let id
= UUID() let angle: Double // 0ʙ360 let x: Double let y: Double let z: Double } struct PlanetsSimulationView: View { @State private var earthAngle: Double = 0 private let timer = Timer.publish(every: 0.02, on: .main, in: .common).autoconnect() // 360°ͷٿͷيಓσʔλΛੜ private let earthOrbit: [OrbitData] = { let a = 100.0 let e = 0.0167 return (0..<360).map { angle in let rad = Double(angle) * Double.pi / 180 let r = a * (1 - e * e) / (1 + e * cos(rad)) let earthX = r * cos(rad) let earthY = r * sin(rad) let earthZ = 0.0 return OrbitData(angle: Double(angle), x: earthX, y: earthY, z: earthZ) } }() -
let rad = Double(angle) * Double.pi / 180 let r
= a * (1 - e * e) / (1 + e * cos(rad)) let earthX = r * cos(rad) let earthY = r * sin(rad) let earthZ = 0.0 return OrbitData(angle: Double(angle), x: earthX, y: earthY, z: earthZ) } }() ... var body: some View { Chart3D { // ଠཅΛϓϩοτ PointMark( x: .value("X", -100.0 * 0.0167), y: .value("Y", 0.0), z: .value("Z", 0.0) ) .foregroundStyle(.orange) // ٿͷيಓ ForEach(earthOrbit) { data in PointMark( x: .value("X", data.x), y: .value("Y", data.y), z: .value("Z", data.z) ) .foregroundStyle(.cyan) }