void MyPrimitive::GeneratePlane(float a_fSize, vector3 a_v3Color) { if (a_fSize < 0.01f) a_fSize = 0.01f; Release(); Init(); float fValue = 0.5f * a_fSize; vector3 pointA(-fValue, -fValue, 0.0f); //0 vector3 pointB(fValue, -fValue, 0.0f); //1 vector3 pointC(fValue, fValue, 0.0f); //2 vector3 pointD(-fValue, fValue, 0.0f); //3 vector3 pointE(fValue, -fValue, -0.001f); //1 vector3 pointF(-fValue, -fValue, -0.001f); //0 vector3 pointG(fValue, fValue, -0.001f); //2 vector3 pointH(-fValue, fValue, -0.001f); //3 //F AddQuad(pointA, pointB, pointD, pointC); //Double sided AddQuad(pointE, pointF, pointG, pointH); CompileObject(a_v3Color); }
void ButtonHandler::updateBlockedSides() { const int EXTENSION = m_separator * 2 + m_buttonBaseSize; // Right QPoint pointA(m_selection.right() + EXTENSION, m_selection.bottom()); QPoint pointB(pointA.x(), m_selection.top()); m_blockedRight = !(m_screenRegions.contains(pointA) && m_screenRegions.contains(pointB)); // Left pointA.setX(m_selection.left() - EXTENSION); pointB.setX(pointA.x()); m_blockedLeft = !(m_screenRegions.contains(pointA) && m_screenRegions.contains(pointB)); // Botton pointA = QPoint(m_selection.left(), m_selection.bottom() + EXTENSION); pointB = QPoint(m_selection.right(), pointA.y()); m_blockedBotton = !(m_screenRegions.contains(pointA) && m_screenRegions.contains(pointB)); // Top pointA.setY(m_selection.top() - EXTENSION); pointB.setY(pointA.y()); m_blockedTop = !(m_screenRegions.contains(pointA) && m_screenRegions.contains(pointB)); // Auxiliar m_oneHorizontalBlocked = (!m_blockedRight && m_blockedLeft) || (m_blockedRight && !m_blockedLeft); m_horizontalyBlocked = (m_blockedRight && m_blockedLeft); m_allSidesBlocked = (m_blockedBotton && m_horizontalyBlocked && m_blockedTop); }
/** * recenters the points of a constant distance towards the center * * @param y bottom most point * @param z left most point * @param x right most point * @param t top most point * @return {@link vector<Ref<ResultPoint> >} describing the corners of the rectangular * region. The first and last points are opposed on the diagonal, as * are the second and third. The first point will be the topmost * point and the last, the bottommost. The second point will be * leftmost and the third, the rightmost */ vector<Ref<ResultPoint> > WhiteRectangleDetector::centerEdges(Ref<ResultPoint> y, Ref<ResultPoint> z, Ref<ResultPoint> x, Ref<ResultPoint> t) { // // t t // z x // x OR z // y y // float yi = y->getX(); float yj = y->getY(); float zi = z->getX(); float zj = z->getY(); float xi = x->getX(); float xj = x->getY(); float ti = t->getX(); float tj = t->getY(); std::vector<Ref<ResultPoint> > corners(4); if (yi < (float)width_/2) { Ref<ResultPoint> pointA(new ResultPoint(ti - CORR, tj + CORR)); Ref<ResultPoint> pointB(new ResultPoint(zi + CORR, zj + CORR)); Ref<ResultPoint> pointC(new ResultPoint(xi - CORR, xj - CORR)); Ref<ResultPoint> pointD(new ResultPoint(yi + CORR, yj - CORR)); corners[0].reset(pointA); corners[1].reset(pointB); corners[2].reset(pointC); corners[3].reset(pointD); } else { Ref<ResultPoint> pointA(new ResultPoint(ti + CORR, tj + CORR)); Ref<ResultPoint> pointB(new ResultPoint(zi + CORR, zj - CORR)); Ref<ResultPoint> pointC(new ResultPoint(xi - CORR, xj + CORR)); Ref<ResultPoint> pointD(new ResultPoint(yi - CORR, yj - CORR)); corners[0].reset(pointA); corners[1].reset(pointB); corners[2].reset(pointC); corners[3].reset(pointD); } return corners; }
int main(int argc, const char *argv[]) { Points pointA(1, 5); Points pointB(2, 6); std::cout << "Program to print the distance between two points" << std::endl; std::cout << "Distance between (" << pointA.x << "," << pointA.y << ")(" << pointB.x << "," << pointB.y << ") = " << distance(pointA, pointB) << std::endl; return 0; }
void Particle_Viewer::translate(float time) { osg::ref_ptr<osg::AnimationPath> path = new osg::AnimationPath; path->setLoopMode( osg::AnimationPath::NO_LOOPING ); osg::AnimationPath::ControlPoint pointA(this->initialPosition); osg::AnimationPath::ControlPoint pointB(this->finalPosition); path->insert( 0.0f, pointA ); path->insert( time, pointB ); osg::ref_ptr<osg::AnimationPathCallback> cb = new osg::AnimationPathCallback( path ); this->setUpdateCallback( cb ); }
int PhysBody::RayCast(int x1, int y1, int x2, int y2, float& normal_x, float& normal_y) const { // TODO 2: Write code to test a ray cast between both points provided. If not hit return -1 // if hit, fill normal_x and normal_y and return the distance between x1,y1 and it's colliding point int ret = -1; b2Vec2 pointA(PIXEL_TO_METERS(x1), PIXEL_TO_METERS(y1)); b2Vec2 pointB(PIXEL_TO_METERS(x2), PIXEL_TO_METERS(y2)); b2RayCastInput input; input.p1.Set(normal_x, normal_y); input.maxFraction = 1.0f; b2Vec2 hitPoint = pointA; return ret; }
void MeaAngleTool::UpdateBisector() { MeaUnitsMgr& units = MeaUnitsMgr::Instance(); // Angles are calculated based on the converted // positions so that screen resolutions are taken // into account. // FPOINT p1 = units.ConvertCoord(m_point1); FPOINT p2 = units.ConvertCoord(m_point2); FPOINT v = units.ConvertCoord(m_vertex); // The bisector angle is the average of the angle made by // each line relative to the x-axis. // // Bisector angle = (angle 1 + angle 2) / 2 // double alphaB = (MeaLayout::GetAngle(v, p1) + MeaLayout::GetAngle(v, p2)) / 2.0; if (units.GetInvertY()) { alphaB = -alphaB; } // Ensure that the bisector is on the acute or obtuse side of the angle. // CPoint pointB(m_vertex.x + static_cast<LONG>(kLengthB * cos(alphaB)), m_vertex.y + static_cast<LONG>(kLengthB * sin(alphaB))); FPOINT pB = units.ConvertCoord(pointB); bool angleSign = MeaLayout::GetAngle(v, p1, p2) >= 0.0; bool bisectorSign = MeaLayout::GetAngle(v, p1, pB) >= 0.0; // If we need to flip the bisector, add 180 degrees and recalc // its location. // if ((angleSign && !bisectorSign) || (!angleSign && bisectorSign)) { alphaB = alphaB + MeaUnits::kPI; pointB.x = m_vertex.x + static_cast<LONG>(kLengthB * cos(alphaB)); pointB.y = m_vertex.y + static_cast<LONG>(kLengthB * sin(alphaB)); } // Position the bisector line based on the calculated point. // m_lineB.SetPosition(m_vertex, pointB); }
QPair<Vector3D,Vector3D> calcBestAxisThroughPoints( const QVector<Vector3D>& points ) { float a[3], b[3]; int n = points.count(); QVector<float> buf; buf.resize(3*n); for (int i = 0; i < n; i++) { buf[i] = points[i].x; buf[n + i] = points[i].y; buf[2*n + i] = points[i].z; } least_squares(n, buf.data(), a, b); least_squares(n, buf.data() + n, a + 1, b + 1); least_squares(n, buf.data() + 2*n, a + 2, b + 2); Vector3D pointA(b[0], b[1], b[2]); Vector3D pointB(a[0]*(n-1) + b[0], a[1]*(n-1) + b[1], a[2]*(n-1) + b[2]); return QPair<Vector3D,Vector3D>(pointA, pointB); }
int CompareShapeFunctions(TPZCompElSide celsideA, TPZCompElSide celsideB) { TPZGeoElSide gelsideA = celsideA.Reference(); TPZGeoElSide gelsideB = celsideB.Reference(); int sideA = gelsideA.Side(); int sideB = gelsideB.Side(); TPZCompEl *celA = celsideA.Element(); TPZCompEl *celB = celsideB.Element(); TPZMultiphysicsElement *MFcelA = dynamic_cast<TPZMultiphysicsElement *>(celA); TPZMultiphysicsElement *MFcelB = dynamic_cast<TPZMultiphysicsElement *>(celB); TPZInterpolatedElement *interA = dynamic_cast<TPZInterpolatedElement *>(MFcelA->Element(0)); TPZInterpolatedElement *interB = dynamic_cast<TPZInterpolatedElement *>(MFcelB->Element(0)); TPZMaterialData dataA; TPZMaterialData dataB; interA->InitMaterialData(dataA); interB->InitMaterialData(dataB); TPZTransform<> tr = gelsideA.NeighbourSideTransform(gelsideB); TPZGeoEl *gelA = gelsideA.Element(); TPZTransform<> trA = gelA->SideToSideTransform(gelsideA.Side(), gelA->NSides()-1); TPZGeoEl *gelB = gelsideB.Element(); TPZTransform<> trB = gelB->SideToSideTransform(gelsideB.Side(), gelB->NSides()-1); int dimensionA = gelA->Dimension(); int dimensionB = gelB->Dimension(); int nSideshapeA = interA->NSideShapeF(sideA); int nSideshapeB = interB->NSideShapeF(sideB); int is; int firstShapeA = 0; int firstShapeB = 0; for (is=0; is<sideA; is++) { firstShapeA += interA->NSideShapeF(is); } for (is=0; is<sideB; is++) { firstShapeB += interB->NSideShapeF(is); } TPZIntPoints *intrule = gelA->CreateSideIntegrationRule(gelsideA.Side(), 4); int nwrong = 0; int npoints = intrule->NPoints(); int ip; for (ip=0; ip<npoints; ip++) { TPZManVector<REAL,3> pointA(gelsideA.Dimension()),pointB(gelsideB.Dimension()), pointElA(gelA->Dimension()),pointElB(gelB->Dimension()); REAL weight; intrule->Point(ip, pointA, weight); int sidedim = gelsideA.Dimension(); TPZFNMatrix<9> jacobian(sidedim,sidedim),jacinv(sidedim,sidedim),axes(sidedim,3); REAL detjac; gelsideA.Jacobian(pointA, jacobian, jacinv, detjac, jacinv); TPZManVector<REAL,3> normal(3,0.), xA(3),xB(3); normal[0] = axes(0,1); normal[1] = -axes(0,0); tr.Apply(pointA, pointB); trA.Apply(pointA, pointElA); trB.Apply(pointB, pointElB); gelsideA.Element()->X(pointElA, xA); gelsideB.Element()->X(pointElB, xB); for (int i=0; i<3; i++) { if(fabs(xA[i]- xB[i])> 1.e-6) DebugStop(); } int nshapeA = 0, nshapeB = 0; interA->ComputeRequiredData(dataA, pointElA); interB->ComputeRequiredData(dataB, pointElB); nshapeA = dataA.phi.Rows(); nshapeB = dataB.phi.Rows(); if(nSideshapeA != nSideshapeB) DebugStop(); TPZManVector<REAL> shapesA(nSideshapeA), shapesB(nSideshapeB); int nwrongkeep(nwrong); int i,j; for(i=firstShapeA,j=firstShapeB; i<firstShapeA+nSideshapeA; i++,j++) { int Ashapeind = i; int Bshapeind = j; int Avecind = -1; int Bvecind = -1; // if A or B are boundary elements, their shapefunctions come in the right order if (dimensionA != sidedim) { Ashapeind = dataA.fVecShapeIndex[i].second; Avecind = dataA.fVecShapeIndex[i].first; } if (dimensionB != sidedim) { Bshapeind = dataB.fVecShapeIndex[j].second; Bvecind = dataB.fVecShapeIndex[j].first; } if (dimensionA != sidedim && dimensionB != sidedim) { // vefify that the normal component of the normal vector corresponds Avecind = dataA.fVecShapeIndex[i].first; Bvecind = dataB.fVecShapeIndex[j].first; REAL vecnormalA = dataA.fNormalVec(0,Avecind)*normal[0]+dataA.fNormalVec(1,Avecind)*normal[1]; REAL vecnormalB = dataB.fNormalVec(0,Bvecind)*normal[0]+dataB.fNormalVec(1,Bvecind)*normal[1]; if(fabs(vecnormalA-vecnormalB) > 1.e-6) { nwrong++; LOGPZ_ERROR(logger, "normal vectors aren't equal") } } shapesA[i-firstShapeA] = dataA.phi(Ashapeind,0); shapesB[j-firstShapeB] = dataB.phi(Bshapeind,0); REAL valA = dataA.phi(Ashapeind,0); REAL valB = dataB.phi(Bshapeind,0); REAL diff = valA-valB; REAL decision = fabs(diff)-1.e-6; if(decision > 0.) { nwrong ++; std::cout << "valA = " << valA << " valB = " << valB << " Avecind " << Avecind << " Bvecind " << Bvecind << " Ashapeind " << Ashapeind << " Bshapeind " << Bshapeind << " sideA " << sideA << " sideB " << sideB << std::endl; LOGPZ_ERROR(logger, "shape function values are different") }
void MyPrimitive::GenerateSphere(float a_fRadius, int a_nSubdivisions, vector3 a_vColor) { //Sets minimum and maximum of subdivisions if (a_nSubdivisions < 1) { GenerateCube(a_fRadius * 2, a_vColor); return; } if (a_nSubdivisions > 6) a_nSubdivisions = 6; //Clean up Memory Release(); Init(); //Your Code Goes Here instead of the next three lines float fValue = 0.5f; vector3 pointA(-fValue, -fValue, fValue); //0 vector3 pointB(fValue, -fValue, fValue); //1 vector3 pointC(-fValue, fValue, fValue); //2 //left to right List of vector3 std::vector<vector3> vectorAB; vectorAB.push_back(pointA); for (int i = 0; i < a_nSubdivisions; i++) { vector3 temp(pointB - pointA); temp /= a_nSubdivisions + 1; temp *= (i + 1); vectorAB.push_back(temp + pointA); } vectorAB.push_back(pointB); //height increments float fHeight = pointC.y - pointA.y; fHeight /= a_nSubdivisions + 1; //List of Lists std::vector<std::vector<vector3>> list; list.push_back(vectorAB); for (int j = 0; j < a_nSubdivisions + 1; j++) { std::vector<vector3> temp = list[0]; float increment = fHeight * (j + 1); for (int i = 0; i < a_nSubdivisions + 2; i++) { temp[i].y += increment; } list.push_back(temp); } //Creating the patch of quads for (int j = 0; j < a_nSubdivisions + 1; j++) { for (int i = 0; i < a_nSubdivisions + 1; i++) { AddQuad(list[j][i], list[j][i + 1], list[j + 1][i], list[j + 1][i + 1]); } } int nVertices = static_cast<int>(m_lVertexPos.size()); //normalizing the vectors to make them round for (int i = 0; i < nVertices; i++) { m_lVertexPos[i] = glm::normalize(m_lVertexPos[i]); m_lVertexPos[i] *= a_fRadius; } //RightSideFace std::vector<vector3> right; for (int i = 0; i < nVertices; i++) { matrix4 rotation; rotation = glm::rotate(matrix4(1.0f), 90.0f, vector3(0.0f, 1.0f, 0.0f)); right.push_back(static_cast <vector3>(rotation * vector4(m_lVertexPos[i], 1.0f))); } for (int i = 0; i < nVertices; i++) { AddVertexPosition(right[i]); } //LeftSideFace std::vector<vector3> left; for (int i = 0; i < nVertices; i++) { matrix4 rotation; rotation = glm::rotate(matrix4(1.0f), -90.0f, vector3(0.0f, 1.0f, 0.0f)); left.push_back(static_cast <vector3>(rotation * vector4(m_lVertexPos[i], 1.0f))); } for (int i = 0; i < nVertices; i++) { AddVertexPosition(left[i]); } //BackSideFace std::vector<vector3> back; for (int i = 0; i < nVertices; i++) { matrix4 rotation; rotation = glm::rotate(matrix4(1.0f), 180.0f, vector3(0.0f, 1.0f, 0.0f)); back.push_back(static_cast <vector3>(rotation * vector4(m_lVertexPos[i], 1.0f))); } for (int i = 0; i < nVertices; i++) { AddVertexPosition(back[i]); } //TopSideFace std::vector<vector3> top; for (int i = 0; i < nVertices; i++) { matrix4 rotation; rotation = glm::rotate(matrix4(1.0f), -90.0f, vector3(1.0f, 0.0f, 0.0f)); top.push_back(static_cast <vector3>(rotation * vector4(m_lVertexPos[i], 1.0f))); } for (int i = 0; i < nVertices; i++) { AddVertexPosition(top[i]); } //BottomSideFace std::vector<vector3> bottom; for (int i = 0; i < nVertices; i++) { matrix4 rotation; rotation = glm::rotate(matrix4(1.0f), 90.0f, vector3(1.0f, 0.0f, 0.0f)); bottom.push_back(static_cast <vector3>(rotation * vector4(m_lVertexPos[i], 1.0f))); } for (int i = 0; i < nVertices; i++) { AddVertexPosition(bottom[i]); } //Compile the object in this color and assign it this name CompileObject(a_vColor); }
int main() { const sf::Time TIME_PER_FRAME = sf::seconds(1.f / 60.f); sf::RenderWindow window(sf::VideoMode(400, 300), "Task 1"); // create the circle and line sf::CircleShape circle(8.f); circle.setFillColor(sf::Color::Red); sf::FloatRect bounds = circle.getLocalBounds(); circle.setOrigin(std::floor(bounds.left + bounds.width / 2.f), std::floor(bounds.top + bounds.height / 2.f)); circle.setPosition(sf::Vector2f(10, 10)); int circleMoveDir = 1; sf::Vector2f pointA(10, 10); sf::Vector2f pointB(150, 150); sf::Vertex line[] = { sf::Vertex(pointA), sf::Vertex(pointB) }; sf::Clock clock; sf::Time timeSinceLastUpdate = sf::Time::Zero; while (window.isOpen()) { sf::Time elapsedTime = clock.restart(); timeSinceLastUpdate += elapsedTime; while (timeSinceLastUpdate > TIME_PER_FRAME) { timeSinceLastUpdate -= TIME_PER_FRAME; // process events sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) { window.close(); } } // update // calculate slope of line float x = pointA.y - pointB.y; float y = pointA.x - pointB.x; float m = (y) ? x / y : 0.f; circle.move(sf::Vector2f(1.f * circleMoveDir, 0.f)); float ypos = m * circle.getPosition().x; circle.setPosition(circle.getPosition().x, ypos); if (circle.getPosition().x >= pointB.x && circle.getPosition().y >= pointB.y) { circle.setPosition(pointB); circleMoveDir = -circleMoveDir; } else if (circle.getPosition().x <= pointA.x && circle.getPosition().y <= pointA.y) { circle.setPosition(pointA); circleMoveDir = -circleMoveDir; } } window.clear(); // draw window.draw(line, 2, sf::Lines); window.draw(circle); window.display(); } return 0; }
TEST(intersection, triangle_tetrahedron) { TIntersectionType it; double area; // create tetrahedron TPoint point0(0.00, 0.00, 0.00); TPoint point1(3.00, 0.00, 0.00); TPoint point2(0.00, 3.00, 0.00); TPoint point3(0.00, 0.00, 3.00); TTetrahedron tetrahedron(point0, point1, point2, point3); // triangle is in tetrahedron TPoint pointA(0.50, 0.50, 0.50); TPoint pointB(0.50, 1.50, 0.50); TPoint pointC(1.50, 0.50, 0.50); TTriangle triangle(pointA, pointB, pointC); xprintf(Msg, "Test - triangle is in tetrahedron\n"); GetIntersection(triangle, tetrahedron, it, area); EXPECT_FLOAT_EQ(area, 0.5); // triangle is greater than tetrahedron, intersection is triangle pointA.SetCoord(-3.0, 2.0, 2.0); pointB.SetCoord(2.0, -3.0, 2.0); pointC.SetCoord(2.0, 2.0, 2.0); triangle.SetPoints(pointA, pointB, pointC); xprintf(Msg, "Test - triangle is greater than tetrahedron, intersection is triangle\n"); GetIntersection(triangle, tetrahedron, it, area); EXPECT_FLOAT_EQ(area, 0.5); // intersection is tetragon pointA.SetCoord(-0.50, 0.50, 1.00); pointB.SetCoord(2.00, 0.50, 1.00); pointC.SetCoord(2.00, 3.00, 1.00); triangle.SetPoints(pointA, pointB, pointC); xprintf(Msg, "Test - intersection is tetragon\n"); GetIntersection(triangle, tetrahedron, it, area); EXPECT_FLOAT_EQ(area, 0.875); // intersection is pentagon pointA.SetCoord(-1.0, 2.00, 1.00); pointB.SetCoord(1.50, 2.00, 1.00); pointC.SetCoord(1.50,-0.5 , 1.00); triangle.SetPoints(pointA, pointB, pointC); xprintf(Msg, "Test - intersection is pentagon\n"); GetIntersection(triangle, tetrahedron, it, area); EXPECT_FLOAT_EQ(area, 0.5+0.5+0.5*3.0/4.0); // intersection is hexagon (plane parallel to x-y) pointA.SetCoord(2.00, 2.00, 0.50); pointB.SetCoord(2.00, -1.00, 0.50); pointC.SetCoord(-1.00, 2.00, 0.50); triangle.SetPoints(pointA, pointB, pointC); xprintf(Msg, "Test - intersection is hexagon (plane parallel to x-y)\n"); GetIntersection(triangle, tetrahedron, it, area); EXPECT_FLOAT_EQ(area, 2.375); // intersection is hexagon pointA.SetCoord(0.25, 2.00, 1.00); pointB.SetCoord(2.25, 1.00, -1.00); pointC.SetCoord(0.25, -1.00, 3.00); triangle.SetPoints(pointA, pointB, pointC); xprintf(Msg, "Test - intersection is hexagon\n"); GetIntersection(triangle, tetrahedron, it, area); EXPECT_FLOAT_EQ(area, 3.477919); }