From 879741fd5025a4ddcfdb1d061ec112d0e06488bd Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Wed, 27 Mar 2024 19:39:34 +0530 Subject: [PATCH 1/3] Add surface area calculation commands for 3d objects Still need to add command for CSA and TSA of cone. Work in progress... --- cogs/maths.py | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/cogs/maths.py b/cogs/maths.py index 15b834ad..c137bada 100644 --- a/cogs/maths.py +++ b/cogs/maths.py @@ -160,6 +160,73 @@ async def volume_cylinder(self, ctx: ApplicationContext, radius: float, height: localembed.set_footer(text=f"Taking π as 22/7\nv = 1/3 x πr²h\n1/3 x π x {radius}² x {height} = {result} cu. units") await ctx.respond(embed=localembed) + # Surface Area Commands + @math.command( + name="surfacearea_cuboid", + description="Find the surface area of a cuboid" + ) + @option(name="length", description="The length of the cuboid", type=float) + @option(name="breadth", description="The breadth of the cuboid", type=float, default=None) + @option(name="height", description="The height/depth of the cuboid", type=float, default=None) + async def surfacearea_cuboid(self, ctx: ApplicationContext, length: float, breadth: float = None, height: float = None): + if (breadth != None and height == None) or (height != None and breadth == None): return await ctx.respond("Both `breadth` and `height` arguments needs to be filled!") + if breadth == None and height == None: + breadth = length + height = length + result = 2 * ((length * breadth) + (breadth * height) + (height * length)) + localembed = discord.Embed(title=f"Surface Area of cuboid (l: {length}, b: {breadth}, h: {height})", description=f"{result} sq. units", color=color) + localembed.set_footer(text=f"a = 2(lb x bh x hl)\n2(({length} x {breadth}) + ({breadth} x {height}) + ({height} x {length})) = {result} sq. units") + await ctx.respond(embed=localembed) + + @math.command( + name="surfacearea_sphere", + description="Find the surface area of a sphere" + ) + @option(name="radius", description="The radius of the sphere", type=float) + async def surfacearea_sphere(self, ctx: ApplicationContext, radius: float): + if radius < 0: return await ctx.respond("The `radius` argument cannot be negative!") + result = 4 * ((22/7) * (radius ** 2)) + localembed = discord.Embed(title=f"Surface Area of sphere of radius {radius} units", description=f"{result} sq. units", color=color) + localembed.set_footer(text=f"Taking π as 22/7\na = 4 x πr²\n4 x π x {radius}² = {result} sq. units") + await ctx.respond(embed=localembed) + + @math.command( + name="surfacearea_hemisphere", + description="Find the surface area of a hemisphere" + ) + @option(name="mode", description="Do you want to calculate for CSA or TSA?", type=str, choices=["CSA", "TSA"]) + @option(name="radius", description="The radius of the hemisphere", type=float) + async def surfacearea_hemisphere(self, ctx: ApplicationContext, mode: str, radius: float): + if radius < 0: return await ctx.respond("The `radius` argument cannot be negative!") + if mode == "CSA": + result = 2 * ((22/7) * (radius ** 2)) + localembed = discord.Embed(title=f"Curved Surface Area of hemisphere of radius {radius} units", description=f"{result} sq. units", color=color) + localembed.set_footer(text=f"Taking π as 22/7\na = 2 x πr²\n4 x π x {radius}² = {result} sq. units") + else: + result = 3 * ((22/7) * (radius ** 2)) + localembed = discord.Embed(title=f"Total Surface Area of hemisphere of radius {radius} units", description=f"{result} sq. units", color=color) + localembed.set_footer(text=f"Taking π as 22/7\na = 3 x πr²\n4 x π x {radius}² = {result} sq. units") + await ctx.respond(embed=localembed) + + @math.command( + name="surfacearea_cylinder", + description="Find the surface area of a cylinder" + ) + @option(name="mode", description="Do you want to calculate for CSA or TSA?", type=str, choices=["CSA", "TSA"]) + @option(name="radius", description="The radius of the cylinder", type=float) + @option(name="height", description="The height of the cylinder", type=float) + async def surfacearea_cylinder(self, ctx: ApplicationContext, mode: str, radius: float, height: float): + if radius < 0 or height < 0: return await ctx.respond("The `radius` and `height` arguments cannot be negative!") + if mode == "CSA": + result = 2 * (22/7) * radius * height + localembed = discord.Embed(title=f"Curved Surface Area of cylinder of radius {radius} units", description=f"{result} sq. units", color=color) + localembed.set_footer(text=f"Taking π as 22/7\na = 2πrh\n2 x π x {radius} x {height} = {result} sq. units") + else: + result = 2 * (22/7) * radius * (radius + height) + localembed = discord.Embed(title=f"Total Surface Area of cylinder of radius {radius} units", description=f"{result} sq. units", color=color) + localembed.set_footer(text=f"Taking π as 22/7\na = 2πr x (r + h)\n2 x π x {radius} x ({radius} + {height}) = {result} sq. units") + await ctx.respond(embed=localembed) + # Initialization def setup(bot): bot.add_cog(Maths(bot)) From 9185a1298b25ad80224e505584bfdc3d5448d800 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Wed, 27 Mar 2024 20:05:30 +0530 Subject: [PATCH 2/3] Add surface area calculation command for cone --- cogs/maths.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/cogs/maths.py b/cogs/maths.py index c137bada..171fe9e5 100644 --- a/cogs/maths.py +++ b/cogs/maths.py @@ -219,14 +219,34 @@ async def surfacearea_cylinder(self, ctx: ApplicationContext, mode: str, radius: if radius < 0 or height < 0: return await ctx.respond("The `radius` and `height` arguments cannot be negative!") if mode == "CSA": result = 2 * (22/7) * radius * height - localembed = discord.Embed(title=f"Curved Surface Area of cylinder of radius {radius} units", description=f"{result} sq. units", color=color) + localembed = discord.Embed(title=f"Curved Surface Area of cylinder (r: {radius}, h: {height})", description=f"{result} sq. units", color=color) localembed.set_footer(text=f"Taking π as 22/7\na = 2πrh\n2 x π x {radius} x {height} = {result} sq. units") else: result = 2 * (22/7) * radius * (radius + height) - localembed = discord.Embed(title=f"Total Surface Area of cylinder of radius {radius} units", description=f"{result} sq. units", color=color) + localembed = discord.Embed(title=f"Total Surface Area of cylinder (r: {radius}, h: {height})", description=f"{result} sq. units", color=color) localembed.set_footer(text=f"Taking π as 22/7\na = 2πr x (r + h)\n2 x π x {radius} x ({radius} + {height}) = {result} sq. units") await ctx.respond(embed=localembed) + @math.command( + name="surfacearea_cone", + description="Find the surface area of a cone" + ) + @option(name="mode", description="Do you want to calculate for CSA or TSA?", type=str, choices=["CSA", "TSA"]) + @option(name="radius", description="The radius of the cone", type=float) + @option(name="height", description="The height of the cone", type=float) + async def surfacearea_cone(self, ctx: ApplicationContext, mode: str, radius: float, height: float): + if radius < 0 or height < 0: return await ctx.respond("The `radius` and `height` arguments cannot be negative!") + slant_height = round(sqrt(radius + height), 3) + if mode == "CSA": + result = (22/7) * radius * slant_height + localembed = discord.Embed(title=f"Curved Surface Area of cone (r: {radius}, h: {height})", description=f"{result} sq. units", color=color) + localembed.set_footer(text=f"Taking π as 22/7\nl = √(r + h)\na = πrl\nπ x {radius} x {slant_height} = {result} sq. units") + else: + result = (22/7) * radius * (slant_height + radius) + localembed = discord.Embed(title=f"Total Surface Area of cone (r: {radius}, h: {height})", description=f"{result} sq. units", color=color) + localembed.set_footer(text=f"Taking π as 22/7\nl = √(r + h)\na = πr x (l + r)\nπ x {radius} x ({slant_height} + {radius}) = {result} sq. units") + await ctx.respond(embed=localembed) + # Initialization def setup(bot): bot.add_cog(Maths(bot)) From 0ff485fd40afb8897326abbd0e4070ffa805325e Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Wed, 27 Mar 2024 20:16:02 +0530 Subject: [PATCH 3/3] Add all new surface area commands to command registry --- config/commands.json | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/config/commands.json b/config/commands.json index 1e80bb7e..d5736509 100644 --- a/config/commands.json +++ b/config/commands.json @@ -768,5 +768,55 @@ "usable_by": "everyone", "disabled": false, "bugged": false + }, + "math surfacearea_cuboid": { + "name": "Cuboid Surface Area", + "description": "Find the surface area of a cuboid.", + "type": "maths", + "cooldown": null, + "args": ["length", "breadth (optional)", "height (optional)"], + "usable_by": "everyone", + "disabled": false, + "bugged": false + }, + "math surfacearea_sphere": { + "name": "Sphere Surface Area", + "description": "Find the surface area of a sphere using radius.", + "type": "maths", + "cooldown": null, + "args": ["radius"], + "usable_by": "everyone", + "disabled": false, + "bugged": false + }, + "math surfacearea_hemisphere": { + "name": "Hemisphere Surface Area", + "description": "Find the surface area of a hemisphere using radius.", + "type": "maths", + "cooldown": null, + "args": ["mode", "radius"], + "usable_by": "everyone", + "disabled": false, + "bugged": false + }, + "math surfacearea_cylinder": { + "name": "Cylinder Surface Area", + "description": "Find the surface area of a cylinder using radius and height.", + "type": "maths", + "cooldown": null, + "args": ["mode", "radius", "height"], + "usable_by": "everyone", + "disabled": false, + "bugged": false + }, + "math surfacearea_cone": { + "name": "Cone Surface Area", + "description": "Find the surface area of a cone using radius and height.", + "type": "maths", + "cooldown": null, + "args": ["mode", "radius", "height"], + "usable_by": "everyone", + "disabled": false, + "bugged": false } }