peterdsharpe / AeroSandbox

Aircraft design optimization made fast through modern automatic differentiation. Composable analysis tools for aerodynamics, propulsion, structures, trajectory design, and much more.
https://peterdsharpe.github.io/AeroSandbox/
MIT License
687 stars 111 forks source link

Feature: Include a `xsec_centroid` function for the WingXSec class (code provided) #133

Open carsonwmoon opened 2 months ago

carsonwmoon commented 2 months ago

Description of Proposed Feature

Feature: include a xsec_centroid function for the WingXSec class like this:

def xsec_centroid(self):
        """
        Computes the WingXSec's centroid.

        Returns: The (dimensional) centroid of the WingXSec.
        """
        return self.airfoil.centroid() * self.chord

Alternatives I Have Considered

It's easy enough without it, but it could be a good addition to the class, especially since it already has a xsec_area function.

Additional Context

A project I was working on needed to know the centroid of a WingXSec object.

peterdsharpe commented 2 months ago

Hi @carsonwmoon ,

This is a good idea! Unfortunately it gets a little bit challenging on the implementation, though, for two reasons:

  1. The twist of the WingXSec should affect the centroid location. This seems easy enough to adjust for, except...
  2. The twist axis is only determined after the WingXSec is integrated into a Wing. (The exact procedure is a bit complicated, but it's described in the WingXSec docstring. You can read it by running asb.WingXSec?; excerpt below).
                The twist axis is computed with the following procedure:

                    * The quarter-chord point of this WingXSec and the following one are identified.

                    * A line is drawn connecting them, and it is normalized to a unit direction vector.

                    * That direction vector is projected onto the geometry Y-Z plane.

                    * That direction vector is now the twist axis.

Because of this, computing the centroid accurately (in a general case) purely from WingXSec quantities is a bit complicated. The provided code is roughly correct in the case of an untwisted wing, but not correct in the general case.

I'll leave this issue open in case others have ideas here, but it seems a bit tricky to do right.

peterdsharpe commented 2 months ago

This also opens up the potential for misunderstanding if the user specifies control_surfaces attached to the WingXSec - do those affect the centroid as they deflect?