void CreateFormattedMessage(uint8_t ID, char* formattedMessage) { char temp2[20]; uint16_t error; uint16_t DataTemp; formattedMessage[0] = '\0'; //Readable format if(clients[ID].format == 0x00) { strcat(formattedMessage,"Not implemented function.\n"); } //CSV format else if(clients[ID].format == 0x01) { error = Get_Distance(); uint162StrDec(formattedMessage, error); strcat(formattedMessage,";"); DataTemp = M_Get_DC(); uint162StrDec(temp2, DataTemp); strcat(temp2,";"); strcat(formattedMessage,temp2); DataTemp = Get_RPM(); uint162StrDec(temp2, DataTemp); strcat(temp2,";\n"); strcat(formattedMessage,temp2); } }
//--------------------------------------------------------- double CSG_Shape_Points::Get_Distance(TSG_Point Point, TSG_Point &Next) { int iPart; double d, Distance; TSG_Point pt; Distance = Get_Distance(Point, Next, 0); for(iPart=1; iPart<m_nParts && Distance!=0.0; iPart++) { if( (d = Get_Distance(Point, pt, iPart)) >= 0.0 && (d < Distance || Distance < 0.0) ) { Distance = d; Next = pt; } } return( Distance ); }
// Angle between two vectors, useful for rotation float Direction::Angle_Distance(const Direction& direction) const { if (!(Get_X_Angle() == direction.Get_X_Angle() && Get_Y_Angle() == direction.Get_Y_Angle() && Get_Distance() == direction.Get_Distance())) { return (float)(acos(Dot(direction) / (Get_Distance() * direction.Get_Distance())) * DEGREES_PER_RADIAN); } else { return (0); } }
//--------------------------------------------------------- double CSG_Shape_Points::Get_Distance(TSG_Point Point, int iPart) { TSG_Point Next; return( Get_Distance(Point, Next, iPart) ); }
//--------------------------------------------------------- bool CShape_Index::On_Execute(void) { CSG_Shapes *pShapes, *pIndex; //----------------------------------------------------- pShapes = Parameters("SHAPES") ->asShapes(); pIndex = Parameters("INDEX") ->asShapes(); //----------------------------------------------------- if( pShapes->is_Valid() ) { int iField = pShapes->Get_Field_Count(); if( pIndex == NULL ) { pIndex = pShapes; } if( pIndex != pShapes ) { pIndex->Create(SHAPE_TYPE_Polygon, _TL("Shape Index"), pShapes); } pIndex->Add_Field(_TL("Area") , SG_DATATYPE_Double); pIndex->Add_Field(_TL("Perimenter") , SG_DATATYPE_Double); pIndex->Add_Field(_TL("P/A") , SG_DATATYPE_Double); pIndex->Add_Field(_TL("P/sqrt(A)") , SG_DATATYPE_Double); pIndex->Add_Field(_TL("Max.Distance") , SG_DATATYPE_Double); pIndex->Add_Field(_TL("D/A") , SG_DATATYPE_Double); pIndex->Add_Field(_TL("D/sqrt(A)") , SG_DATATYPE_Double); pIndex->Add_Field(_TL("Shape Index") , SG_DATATYPE_Double); for(int iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++) { CSG_Shape_Polygon *pShape = (CSG_Shape_Polygon *)pShapes->Get_Shape(iShape); double Area = pShape->Get_Area(); double Perimeter = pShape->Get_Perimeter(); double Distance = Get_Distance(pShape); if( Perimeter > 0.0 && Distance > 0.0 ) { if( pIndex != pShapes ) { pShape = (CSG_Shape_Polygon *)pIndex->Add_Shape(pShape, SHAPE_COPY_ATTR); } pShape->Set_Value(iField + 0, Area); pShape->Set_Value(iField + 1, Perimeter); pShape->Set_Value(iField + 2, Perimeter / Area); pShape->Set_Value(iField + 3, Perimeter / sqrt(Area)); pShape->Set_Value(iField + 4, Distance); pShape->Set_Value(iField + 5, Distance / Area); pShape->Set_Value(iField + 6, Distance / sqrt(Area)); pShape->Set_Value(iField + 7, Perimeter / (2.0 * sqrt(M_PI * Area))); } } if( pIndex == pShapes ) { DataObject_Update(pShapes); } return( pIndex->is_Valid() ); } //----------------------------------------------------- return( false ); }
//--------------------------------------------------------- TSG_Intersection CSG_Shape_Line::On_Intersects(CSG_Shape *pShape) { //----------------------------------------------------- if( pShape->Get_Type() == SHAPE_TYPE_Point || pShape->Get_Type() == SHAPE_TYPE_Points ) { bool bIn = false; bool bOut = false; for(int iPart=0; iPart<m_nParts; iPart++) { for(int jPart=0; jPart<pShape->Get_Part_Count(); jPart++) { for(int jPoint=1; jPoint<pShape->Get_Point_Count(jPart); jPoint++) { TSG_Point Point; if( Get_Distance(pShape->Get_Point(jPoint, jPart), Point, iPart) == 0.0 ) { bIn = true; } else { bOut = true; } if( bIn && bOut ) { return( INTERSECTION_Overlaps ); } } } } if( bIn ) { return( INTERSECTION_Contained ); } } //----------------------------------------------------- else if( pShape->Get_Type() == SHAPE_TYPE_Line ) { TSG_Point iA, iB, jA, jB, Crossing; for(int iPart=0; iPart<m_nParts; iPart++) { if( Get_Point_Count(iPart) > 1 ) { iA = Get_Point(0, iPart); for(int iPoint=1; iPoint<Get_Point_Count(iPart); iPoint++) { iB = iA; iA = Get_Point(iPoint, iPart); for(int jPart=0; jPart<pShape->Get_Part_Count(); jPart++) { if( pShape->Get_Point_Count(jPart) > 1 ) { jA = pShape->Get_Point(0, jPart); for(int jPoint=1; jPoint<pShape->Get_Point_Count(jPart); jPoint++) { jB = jA; jA = pShape->Get_Point(jPoint, jPart); if( SG_Get_Crossing(Crossing, iA, iB, jA, jB) ) { return( INTERSECTION_Overlaps ); } } } } } } } } return( INTERSECTION_None ); }