Skip to content

Reply To: How to create 2D triangle ?

#6166
Fany
Participant

Hi Adrian, I was creating the 2D triangle by my own triangle functor. But the visualization result showed my functor did not work. What could be the problems here? By the way, when will the next release be ?
`
// creating the triangle
template <typename S>
IndicatorTriangle2D<S>::IndicatorTriangle2D(Vector<S,2> PointA, Vector<S,2> PointB, Vector<S,2> PointC)
: _PointA(PointA), _PointB(PointB), _PointC(PointC)
{
// S AB=std::sqrt(std::pow(_PointB[0]-_PointA[0], 2)+std::pow(_PointB[1]-_PointA[1], 2));
// S AC=std::sqrt(std::pow(_PointC[0]-_PointA[0], 2)+std::pow(_PointC[1]-_PointA[1], 2));
// S BC=std::sqrt(std::pow(_PointB[0]-_PointC[0], 2)+std::pow(_PointB[1]-_PointC[1], 2));
// S halfperi=0.5*(AB+AC+BC);
// S temp=halfperi*(halfperi-AB)*(halfperi-AC)*(halfperi-BC);
// this->_circumRadius = 0.25*AB*AC*BC/std::sqrt(temp);

this->_myMin = { std::min(_PointA[0], std::min(_PointB[0], _PointC[0])), std::min(_PointA[1], std::min(_PointB[1], _PointC[1]))};
this->_myMax = { std::max(_PointA[0], std::max(_PointB[0], _PointC[0])), std::max(_PointA[1], std::max(_PointB[1], _PointC[1]))};
// this->_theta = theta * M_PI/180.;

_ab = _PointB – _PointA;
_bc = _PointC – _PointB;
_ca = _PointA – _PointC;

}

template <typename S>
bool IndicatorTriangle2D<S>::operator()(bool output[], const S input[])
{
Vector<S, 2> _Point ;
_Point[0] = input[0];
_Point[1] = input[1]; //any point M
Vector<S, 2> _am=_Point – _PointA ;
Vector<S, 2> _bm=_Point – _PointB ;
Vector<S, 2> _cm=_Point – _PointC ;

S S_ABM = fabs(_ab[1]*_am[0]-_ab[0]*_am[1])/2. ; // the area of triangle ABM;
S S_BCM = fabs(_bc[1]*_bm[0]-_ca[0]*_bm[1])/2. ; // the area of triangle BCM;
S S_CAM = fabs(_ca[1]*_cm[0]-_ca[0]*_cm[1])/2. ; // the area of triangle CAM;
S Sum = fabs(_ca[1]*_ab[0]-_ca[0]*_ab[1])/2. ; // the area of triangle CAM;

output[0] = util::approxEqual(S_ABM + S_BCM + S_CAM, Sum) ;
return true;
}

template <typename S>
IndicatorTriangle2D<S>* createIndicatorTriangle2D(XMLreader const& params, bool verbose)
{
OstreamManager clout(std::cout,”createIndicatorTriangle2D”);
params.setWarningsOn(verbose);

Vector<S,2> PointA;
Vector<S,2> PointB;
Vector<S,2> PointC;

std::stringstream xmlCenter( params.getAttribute(“PointA”) );
xmlCenter >> PointA[0] >> PointA[1]>> PointB[0] >> PointB[1]>> PointC[0] >> PointC[1];

// std::stringstream xmlRadius( params.getAttribute(“length”) );
// xmlRadius >> xLength >> yLength;

return new IndicatorCuboid2D<S>(PointA, PointB, PointC);
}