@@ -1064,16 +1064,87 @@ function PGP.SolidFrustum(turtle::Turtle{FT,UT}; length::FT = one(FT), width::FT
10641064end
10651065
10661066
1067- function Ellipsoid! (turtle:: Turtle{FT,UT} ; length:: FT = one (FT), width:: FT = one (FT),
1068- height:: FT = one (FT), n:: Int = 20 , move = false , kwargs... ) where {FT,UT}
1069- @error " Ellipsoid not implemented yet"
1067+ """
1068+ Ellipsoid!(turtle; length = 1.0, width = 1.0, height = 1.0, n = 20, move = false, kwargs...)
1069+
1070+ Generate a solid ellipsoid in front of the turtle and feed it to a turtle.
1071+
1072+ ## Arguments
1073+ - `turtle`: The turtle that we feed the solid ellipsoid to.
1074+ - `length`: Length of the solid ellipsoid along the head axis.
1075+ - `width`: Width of the solid ellipsoid along the arm axis.
1076+ - `height`: Height of the solid ellipsoid along the up axis.
1077+ - `n`: Number of latitude and azimuth subdivisions. The mesh has `2n(n-1)` triangles.
1078+ - `move`: Whether to move the turtle forward or not (`true` or `false`).
1079+ - `kwargs`: Properties to be set per triangle in the mesh.
1080+
1081+ ## Details
1082+ A mesh will be generated with `2n(n-1)` triangles that approximate the solid ellipsoid.
1083+ The ellipsoid will be generated in front of the turtle, with the base centered at the
1084+ turtle's current position. The `length` argument refers to the axis aligned with the head
1085+ axis of the turtle, whereas `width` refers to the arm axis and `height` to the up axis.
1086+
1087+ When `move = true`, the turtle will be moved forward by a distance equal to `length`.
1088+
1089+ ## Return
1090+ Returns `nothing` but modifies the `turtle` as a side effect.
1091+
1092+ ## Examples
1093+ ```jldoctest
1094+ julia> turtle = Turtle();
1095+
1096+ julia> e = Ellipsoid!(turtle; length = 1.0, width = 0.5, height = 0.5, n = 20);
1097+ ```
1098+ """
1099+ function PGP. Ellipsoid! (turtle:: Turtle{FT,UT} ; length:: FT = one (FT), width:: FT = one (FT),
1100+ height:: FT = one (FT), n:: Int = 20 , move = false , kwargs... ) where {FT,UT}
1101+ trans = transformation (turtle, PGP. Vec (height / FT (2 ), width / FT (2 ), length / FT (2 )))
1102+ PGP. Ellipsoid! (PGP. Mesh (turtle), trans; n = n)
1103+ ntri = 2 n * (n - 1 )
1104+ for (k, v) in kwargs
1105+ PGP. add_property! (PGP. Mesh (turtle), k, v, ntri)
1106+ end
1107+ move && f! (turtle, length)
10701108 return nothing
10711109end
10721110
1073- function Ellipsoid (turtle:: Turtle{FT,UT} ; length:: FT = one (FT), width:: FT = one (FT),
1074- height:: FT = one (FT), n:: Int = 20 , move = false ) where {FT,UT}
1075- @error " Ellipsoid not implemented yet"
1076- return nothing
1111+ """
1112+ Ellipsoid(turtle; length = 1.0, width = 1.0, height = 1.0, n = 20, move = false)
1113+
1114+ Generate a solid ellipsoid in front of the turtle and return it.
1115+
1116+ ## Arguments
1117+ - `turtle`: The turtle which state is used to create the solid ellipsoid.
1118+ - `length`: Length of the solid ellipsoid along the head axis.
1119+ - `width`: Width of the solid ellipsoid along the arm axis.
1120+ - `height`: Height of the solid ellipsoid along the up axis.
1121+ - `n`: Number of latitude and azimuth subdivisions. The mesh has `2n(n-1)` triangles.
1122+ - `move`: Whether to move the turtle forward or not (`true` or `false`).
1123+
1124+ ## Details
1125+ A mesh will be generated with `2n(n-1)` triangles that approximate the solid ellipsoid.
1126+ The ellipsoid will be generated in front of the turtle, with the base centered at the
1127+ turtle's current position. The `length` argument refers to the axis aligned with the head
1128+ axis of the turtle, whereas `width` refers to the arm axis and `height` to the up axis.
1129+
1130+ When `move = true`, the turtle will be moved forward by a distance equal to `length`.
1131+
1132+ ## Return
1133+ Returns a triangular mesh (object of type `Mesh`).
1134+
1135+ ## Examples
1136+ ```jldoctest
1137+ julia> turtle = Turtle();
1138+
1139+ julia> e = Ellipsoid(turtle; length = 1.0, width = 0.5, height = 0.5, n = 20);
1140+ ```
1141+ """
1142+ function PGP. Ellipsoid (turtle:: Turtle{FT,UT} ; length:: FT = one (FT), width:: FT = one (FT),
1143+ height:: FT = one (FT), n:: Int = 20 , move = false ) where {FT,UT}
1144+ trans = transformation (turtle, PGP. Vec (height / FT (2 ), width / FT (2 ), length / FT (2 )))
1145+ e = PGP. Ellipsoid (trans; n = n)
1146+ move && f! (turtle, length)
1147+ return e
10771148end
10781149
10791150
0 commit comments