0 votes

I know that it has something to do with geometry, and I know it uses the PI number because of the radius, but I don't know the calculation I have to do. I want to know the shape's surface area because I need to change it's vertical size and I know I can do it by getting the surface area square root (correct me if I'm wrong about that). Well any help will be good for me, and I hope it is possible to calculate. It seems totally calculable though.

Godot version 3.5.1
in Engine by (12 points)

1 Answer

+1 vote

A capsule is really just a rectangle with a 1/2 circle on either end. So, as far as calculating the area, it'd simply be:

  • The area of the rectangle (width x height)
  • The area of a full circle with a diameter matching the width of the rectangle

In Godot's definition of a CapsuleShape2D you define both a radius and a height value. The radius is the radius of the 1/2 circle on each end. The height is the height of the rectangle between the 2, 1/2 circles. So, a CapsuleShape2D with a height of 0 is essentially just a circle (with a zero height rectangle between the 2 halves).

So, for a real example, let's say we have a CapsuleShape2D defined as follows:

Radius: 10
Height: 20

So, we have the following primitive shapes

  • 1 complete circle with a radius of 10
  • 1 rectangle with a width of 20 (radius * 2) and height of 20

From that, just calculate the areas of the 2 shapes.

  • For the circle, that'd be PI * radius squared, so 314.6
  • For the rectangle, that'd be width x height, so 400

Add those together to get the area of the capsule -> 714.6

by (19,268 points)
edited by

Thank you for the help, but I found out that for the capsule shape height follow the vertical size of the thing I was using I just needed to take the thing vertical size and subtract by the double of the capsule shape radius.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.