-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
195 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/CelestialObject.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/kotlin/io/github/addoncommunity/galactifun/serial/CollectionBlockStorageDataType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/kotlin/io/github/addoncommunity/galactifun/serial/MiscBlockStorageDataType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
src/main/kotlin/io/github/addoncommunity/galactifun/units/SphericalPosition.kt
This file was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
src/main/kotlin/io/github/addoncommunity/galactifun/units/coordiantes/CartesianVector.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.github.addoncommunity.galactifun.units.coordiantes | ||
|
||
import io.github.addoncommunity.galactifun.units.Angle.Companion.radians | ||
import io.github.addoncommunity.galactifun.units.Distance | ||
import io.github.addoncommunity.galactifun.units.Distance.Companion.meters | ||
import kotlin.math.atan2 | ||
import kotlin.math.sqrt | ||
|
||
data class CartesianVector( | ||
val x: Distance, | ||
val y: Distance | ||
) { | ||
|
||
val polar by lazy { | ||
val theta = atan2(y.meters, x.meters).radians | ||
PolarVector(length, theta) | ||
} | ||
|
||
val length by lazy { | ||
sqrt(x.meters * x.meters + y.meters * y.meters).meters | ||
} | ||
|
||
operator fun plus(other: CartesianVector): CartesianVector { | ||
return CartesianVector(x + other.x, y + other.y) | ||
} | ||
|
||
operator fun minus(other: CartesianVector): CartesianVector { | ||
return CartesianVector(x - other.x, y - other.y) | ||
} | ||
|
||
operator fun times(scalar: Double): CartesianVector { | ||
return CartesianVector(x * scalar, y * scalar) | ||
} | ||
|
||
operator fun div(scalar: Double): CartesianVector { | ||
return CartesianVector(x / scalar, y / scalar) | ||
} | ||
|
||
fun distanceTo(other: CartesianVector): Distance { | ||
val term1 = (x - other.x).meters | ||
val term2 = (y - other.y).meters | ||
return sqrt(term1 * term1 + term2 * term2).meters | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/kotlin/io/github/addoncommunity/galactifun/units/coordiantes/PolarVector.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.github.addoncommunity.galactifun.units.coordiantes | ||
|
||
import io.github.addoncommunity.galactifun.units.Angle | ||
import io.github.addoncommunity.galactifun.units.Distance | ||
import io.github.addoncommunity.galactifun.units.cos | ||
import io.github.addoncommunity.galactifun.units.sin | ||
|
||
data class PolarVector( | ||
val radius: Distance, | ||
val angle: Angle | ||
) { | ||
|
||
val cartesian: CartesianVector by lazy { | ||
CartesianVector( | ||
x = radius * cos(angle), | ||
y = radius * sin(angle) | ||
) | ||
} | ||
|
||
operator fun times(scalar: Double): PolarVector { | ||
return PolarVector(radius * scalar, angle * scalar) | ||
} | ||
|
||
operator fun div(scalar: Double): PolarVector { | ||
return PolarVector(radius / scalar, angle / scalar) | ||
} | ||
|
||
fun distanceTo(other: PolarVector): Distance { | ||
return cartesian.distanceTo(other.cartesian) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/kotlin/io/github/addoncommunity/galactifun/units/coordiantes/SphericalVector.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.github.addoncommunity.galactifun.units.coordiantes | ||
|
||
import io.github.addoncommunity.galactifun.units.Angle | ||
import io.github.addoncommunity.galactifun.units.Distance | ||
import io.github.addoncommunity.galactifun.units.Distance.Companion.meters | ||
import io.github.addoncommunity.galactifun.units.cos | ||
import io.github.addoncommunity.galactifun.units.sin | ||
import org.joml.Vector3d | ||
|
||
data class SphericalVector( | ||
val rightAscension: Angle, | ||
val declination: Angle, | ||
val distance: Distance | ||
) { | ||
|
||
private val cartesianPosition by lazy { | ||
val x = distance * sin(declination) * cos(rightAscension) | ||
val y = distance * sin(declination) * sin(rightAscension) | ||
val z = distance * cos(declination) | ||
Vector3d(x.meters, y.meters, z.meters) | ||
} | ||
|
||
// What? I'm not afraid of a few trigonometric functions and a square root or two | ||
fun distanceTo(other: SphericalVector): Distance { | ||
return cartesianPosition.distance(other.cartesianPosition).meters | ||
} | ||
} |
Oops, something went wrong.