TexGen
SectionPowerEllipse.cpp
Go to the documentation of this file.
1/*=============================================================================
2TexGen: Geometric textile modeller.
3Copyright (C) 2006 Martin Sherburn
4
5This program is free software; you can redistribute it and/or
6modify it under the terms of the GNU General Public License
7as published by the Free Software Foundation; either version 2
8of the License, or (at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18=============================================================================*/
19
20#include "PrecompiledHeaders.h"
21#include "SectionPowerEllipse.h"
22using namespace TexGen;
23
24CSectionPowerEllipse::CSectionPowerEllipse(double dWidth, double dHeight, double dPower, double dXOffset)
25: m_dWidth(dWidth)
26, m_dHeight(dHeight)
27, m_dPower(dPower)
28, m_dXOffset(dXOffset)
29{
30}
31
33{
34}
35
36bool CSectionPowerEllipse::operator == (const CSection &CompareMe) const
37{
38 if (CompareMe.GetType() != GetType())
39 return false;
40 return m_dWidth == ((CSectionPowerEllipse*)&CompareMe)->m_dWidth &&
41 m_dHeight == ((CSectionPowerEllipse*)&CompareMe)->m_dHeight &&
42 m_dPower == ((CSectionPowerEllipse*)&CompareMe)->m_dPower &&
43 m_dXOffset == ((CSectionPowerEllipse*)&CompareMe)->m_dXOffset;
44}
45
47: CSection(Element)
48{
49 Element.Attribute("Width", &m_dWidth);
50 Element.Attribute("Height", &m_dHeight);
51 Element.Attribute("Power", &m_dPower);
52 Element.Attribute("XOffset", &m_dXOffset);
53}
54
55void CSectionPowerEllipse::PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType) const
56{
57 CSection::PopulateTiXmlElement(Element, OutputType);
58 Element.SetAttribute("Width", stringify(m_dWidth));
59 Element.SetAttribute("Height", stringify(m_dHeight));
60 Element.SetAttribute("Power", stringify(m_dPower));
61 Element.SetAttribute("XOffset", stringify(m_dXOffset));
62}
63
65{
66 double dX, dY;
67 if ( t <= 0.25 || t >= 0.75 )
68 dX = (0.5*m_dWidth - m_dXOffset)*cos(t*2*PI) + m_dXOffset;
69 else
70 dX = (0.5*m_dWidth + m_dXOffset)*cos(t*2*PI) + m_dXOffset;
71
72 if ( t <= 0.5 )
73 dY = 0.5*m_dHeight*pow(sin(t*2*PI), m_dPower);
74 else
75 dY = -0.5*m_dHeight*pow(-sin(t*2*PI), m_dPower);
76
77 return XY( dX, dY );
78
79 /*if (t <= 0.5)
80 return XY(0.5*m_dWidth*cos(t*2*PI), 0.5*m_dHeight*pow(sin(t*2*PI), m_dPower));
81 else
82 return XY(0.5*m_dWidth*cos(t*2*PI), -0.5*m_dHeight*pow(-sin(t*2*PI), m_dPower));*/
83}
84
86{
87 return "PowerEllipse(W:" + stringify(m_dWidth) + ",H:" + stringify(m_dHeight) + ",P:" + stringify(m_dPower) + ")";
88}
89
90double CSectionPowerEllipse::GetTangent( double t ) const
91{
92 if ( t <= 0.25 )
93 {
94 return( (m_dHeight * m_dPower * cos(t*2*PI) * pow(sin(t*2*PI), m_dPower-2)) / ( -2.0 * (0.5*m_dWidth - m_dXOffset)) );
95 }
96 else if ( t > 0.25 && t <= 0.5 )
97 {
98 return( (m_dHeight * m_dPower * cos(t*2*PI) * pow(sin(t*2*PI), m_dPower-2)) / ( -2.0 * (0.5*m_dWidth + m_dXOffset)) );
99 }
100 else if ( t > 0.5 && t < 0.75 )
101 {
102 return( (m_dHeight * m_dPower * cos(t*2*PI) * pow(-sin(t*2*PI), m_dPower-1)) / ( -2.0 * (0.5*m_dWidth + m_dXOffset) * sin(t*2*PI)) );
103 }
104 else
105 {
106 return( (m_dHeight * m_dPower * cos(t*2*PI) * pow(-sin(t*2*PI), m_dPower-1)) / ( -2.0 * (0.5*m_dWidth - m_dXOffset) * sin(t*2*PI)) );
107 }
108}
109
110
111
112
Abstract base class respresenting a yarn cross-section.
Definition: Section.h:31
virtual void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType) const
Used for saving data to XML.
Definition: Section.cpp:51
virtual string GetType() const =0
Derived class should return the class name.
string GetType() const
Derived class should return the class name.
string GetDefaultName() const
Get the default name to assign to a section.
bool operator==(const CSection &CompareMe) const
Overloaded equality operator to determine if two sections are the same.
CSectionPowerEllipse(double dWidth, double dHeight, double dPower, double dXOffset=0.0)
double GetTangent(double t) const
void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType) const
Used for saving data to XML.
XY GetPoint(double t) const
Get a point lying on the perimeter correspending to parametric value t.
#define PI
Definition: mymath.h:30
Namespace containing a series of customised math operations not found in the standard c++ library.
OUTPUT_TYPE
Definition: Misc.h:105
std::string stringify(const T &x, int iPrecision=12, bool bScientific=true)
Function to convert a value (e.g. int, double, etc...) to a string.
Definition: Misc.h:50
Struct for representing points in 2D space.
Definition: mymath.h:103