Ignore:
Timestamp:
11/27/20 20:54:50 (4 years ago)
Author:
Maciej Komosinski
Message:
  • fS: comma as an intuitive separator in genotype instead of weird symbols ;'
  • other minor refactorizations
Location:
cpp/frams/model/geometry
Files:
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • cpp/frams/model/geometry/geometryutils.cpp

    r1026 r1032  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    369369        return M_PI * ((3 * (a+b)) - sqrt((3*a + b) * (a + 3*b)));
    370370}
     371
     372double GeometryUtils::calculateSolidVolume(Part * part)
     373{
     374        double radiiProduct = part->scale.x * part->scale.y * part->scale.z;
     375        switch (part->shape)
     376        {
     377                case Part::Shape::SHAPE_CUBOID:
     378                        return 8.0 * radiiProduct;
     379                case Part::Shape::SHAPE_CYLINDER:
     380                        return  2.0 * M_PI * radiiProduct;
     381                case Part::Shape::SHAPE_ELLIPSOID:
     382                        return  (4.0 / 3.0) * M_PI * radiiProduct;
     383                default:
     384                        logMessage("GeometryUtils", "calculateSolidVolume", LOG_ERROR, "Unsupported part shape");
     385                        return -1;
     386        }
     387}
     388
     389bool GeometryUtils::isSolidPartScaleValid(const Part::Shape &partShape, const Pt3D &scale)
     390{
     391        Part *tmpPart = new Part(partShape);
     392        tmpPart->scale = scale;
     393        double volume = GeometryUtils::calculateSolidVolume(tmpPart);
     394
     395        Part_MinMaxDef minP = Model::getMinPart();
     396        Part_MinMaxDef maxP = Model::getMaxPart();
     397
     398        if (volume > maxP.volume || minP.volume > volume)
     399                return false;
     400        if (scale.x < minP.scale.x || scale.y < minP.scale.y || scale.z < minP.scale.z)
     401                return false;
     402        if (scale.x > maxP.scale.x || scale.y > maxP.scale.y || scale.z > maxP.scale.z)
     403                return false;
     404
     405        if (partShape == Part::Shape::SHAPE_ELLIPSOID && scale.maxComponentValue() != scale.minComponentValue()) // When any radius has a different value than the others
     406                return false;
     407        if (partShape == Part::Shape::SHAPE_CYLINDER && scale.y != scale.z) // If base radii have different values
     408                return false;
     409        return true;
     410}
  • cpp/frams/model/geometry/geometryutils.h

    r286 r1032  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    177177        double ellipsoidArea(const double a, const double b, const double c);
    178178        double ellipsePerimeter(const double a, const double b);
     179
     180        double calculateSolidVolume(Part *part);
     181        bool isSolidPartScaleValid(const Part::Shape &partShape, const Pt3D &scale);
    179182}
    180183
  • cpp/frams/model/geometry/part_distance_estimator.h

    r1031 r1032  
    5656                /// tmpPart1 and tmpPart2 are copied for purpose and should not be passed as reference
    5757                /// This function can change some of the properties of those parts
     58                /// tmpPart1 will be approximated by surface points.
     59                /// The collision between the parts is detected when any of those points is inside tmpPart2
     60                /// If tmpPart1 and tmpPart2 are swapped, the calculated distance may slightly differ
    5861                Pt3D directionVersor = tmpPart1.p - tmpPart2.p;
    5962                directionVersor.normalize();
    6063
    61                 tmpPart1.p = Pt3D(0);
    62                 tmpPart2.p = Pt3D(0);
     64                tmpPart1.p = Pt3D_0;
     65                tmpPart2.p = Pt3D_0;
    6366
    6467                static double CBRT_3 = std::cbrt(3);
Note: See TracChangeset for help on using the changeset viewer.