2024-01-24 16:16:24 +00:00
|
|
|
module Engine
|
|
|
|
|
2024-01-26 16:14:32 +00:00
|
|
|
export Construction, mprod
|
2024-01-24 16:16:24 +00:00
|
|
|
|
2024-01-26 16:14:32 +00:00
|
|
|
import Subscripts
|
2024-01-24 16:16:24 +00:00
|
|
|
using LinearAlgebra
|
2024-01-26 16:14:32 +00:00
|
|
|
using AbstractAlgebra
|
2024-01-24 16:16:24 +00:00
|
|
|
using Groebner
|
|
|
|
|
2024-01-26 16:14:32 +00:00
|
|
|
# --- primitve elements ---
|
|
|
|
|
|
|
|
mutable struct Point{T}
|
|
|
|
coords::Union{Vector{MPolyRingElem{T}}, Nothing}
|
|
|
|
vec::Union{Vector{MPolyRingElem{T}}, Nothing}
|
|
|
|
|
|
|
|
## [to do] constructor argument never needed?
|
|
|
|
Point{T}(vec::Union{Vector{MPolyRingElem{T}}, Nothing} = nothing) where T = new(vec)
|
|
|
|
end
|
|
|
|
|
|
|
|
coordnames(_::Point) = [:xₚ, :yₚ, :zₚ]
|
|
|
|
|
|
|
|
function buildvec(pt::Point, coordqueue)
|
|
|
|
pt.coords = splice!(coordqueue, 1:3)
|
|
|
|
coordring = parent(coordqueue[1])
|
|
|
|
pt.vec = [one(coordring), dot(pt.coords, pt.coords), pt.coords...]
|
|
|
|
end
|
|
|
|
|
|
|
|
mutable struct Sphere{T}
|
|
|
|
coords::Union{Vector{MPolyRingElem{T}}, Nothing}
|
|
|
|
vec::Union{Vector{MPolyRingElem{T}}, Nothing}
|
2024-01-24 16:16:24 +00:00
|
|
|
|
2024-01-26 16:14:32 +00:00
|
|
|
Sphere{T}(vec::Union{Vector{MPolyRingElem{T}}, Nothing} = nothing) where T = new(vec)
|
2024-01-24 16:16:24 +00:00
|
|
|
end
|
|
|
|
|
2024-01-26 16:14:32 +00:00
|
|
|
coordnames(_::Sphere) = [:rₛ, :sₛ, :xₛ, :yₛ, :zₛ]
|
|
|
|
|
|
|
|
function buildvec(sph::Sphere, coordqueue)
|
|
|
|
sph.coords = splice!(coordqueue, 1:5)
|
|
|
|
sph.vec = sph.coords
|
|
|
|
end
|
|
|
|
|
|
|
|
# --- primitive relations ---
|
|
|
|
|
|
|
|
abstract type Relation{T} end
|
|
|
|
|
|
|
|
mprod(v, w) = v[1]*w[2] + w[1]*v[2] - dot(v[3:end], w[3:end])
|
|
|
|
|
|
|
|
struct LiesOn{T} <: Relation{T}
|
|
|
|
pt::Point{T}
|
|
|
|
sph::Sphere{T}
|
|
|
|
end
|
|
|
|
|
|
|
|
struct AlignsWithBy{T} <: Relation{T}
|
|
|
|
sph_v::Sphere{T}
|
|
|
|
sph_w::Sphere{T}
|
|
|
|
cos_angle::T
|
|
|
|
end
|
|
|
|
|
|
|
|
# --- constructions ---
|
|
|
|
|
|
|
|
mutable struct Construction{T}
|
|
|
|
points::Vector{Point{T}}
|
|
|
|
spheres::Vector{Sphere{T}}
|
|
|
|
|
|
|
|
Construction{T}(; points = Point{T}[], spheres = Sphere{T}[]) where T = new{T}(points, spheres)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Base.push!(ctx::Construction{T}, elem::Point{T}) where T
|
|
|
|
push!(ctx.points, elem)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Base.push!(ctx::Construction{T}, elem::Sphere{T}) where T
|
|
|
|
push!(ctx.spheres, elem)
|
|
|
|
end
|
|
|
|
|
|
|
|
function realize(ctx::Construction{T}) where T
|
|
|
|
# collect variable names
|
|
|
|
allcoordnames = Symbol[]
|
|
|
|
elements = vcat(ctx.points, ctx.spheres)
|
|
|
|
for (index, elem) in enumerate(elements)
|
|
|
|
subscript = Subscripts.sub(string(index))
|
|
|
|
append!(allcoordnames,
|
|
|
|
[Symbol(name, subscript) for name in coordnames(elem)]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
# construct coordinate ring
|
|
|
|
coordring, coordqueue = polynomial_ring(parent_type(T)(), allcoordnames)
|
2024-01-24 16:16:24 +00:00
|
|
|
|
2024-01-26 16:14:32 +00:00
|
|
|
# construct coordinate vectors
|
|
|
|
for elem in elements
|
|
|
|
buildvec(elem, coordqueue)
|
2024-01-24 16:16:24 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2024-01-26 16:14:32 +00:00
|
|
|
# ~~~ sandbox setup ~~~
|
2024-01-24 16:16:24 +00:00
|
|
|
|
2024-01-26 16:14:32 +00:00
|
|
|
a = Engine.Point{Rational{Int64}}()
|
|
|
|
b = Engine.Point{Rational{Int64}}()
|
|
|
|
s = Engine.Sphere{Rational{Int64}}()
|
|
|
|
ctx = Engine.Construction{Rational{Int64}}(points = [a])
|
|
|
|
Engine.push!(ctx, b)
|
|
|
|
Engine.push!(ctx, s)
|