Example #1
0
int main(int argc, char *argv[])
{
	int n = atoi(argv[1]);
	int i,testSq,testTri;

	for (i=1; i<=n; i++)
	{
		testSq = isSquare(i);
	
		if (testSq == 1)
		{
			printf("%d is a square number!\n", i);
			testTri = isTriangle(i);
			if (testTri == 1)
			{
				printf("%d is also a Triangular Number!\n", i);
			}
			else
			{
				printf("But is not also a triangular number...\n");
			}
		}
		else
		{
			 printf("%d is neither a square or triangular number.\n", i);
		}
	}
	return 0;
}
int getAffineIndex(vector<vector<Point2f> > warpedTriangles, int i, int j)
{
    for (int k = 0; k < warpedTriangles.size(); k++)
    {
        if (isTriangle(warpedTriangles[k], double(i), double(j)))
        {
            /* visually check if triangle picking is correct
            if (i % 50 == 0 && j % 50 == 0)
            {
                vector<Point2f> curTriangle = warpedTriangles[k];
                 Mat hey = faceIm_0.clone();
                 line(hey, Point(i,j), Point(i+1,j+1), RED, 5);
                 
                 line(hey, Point(curTriangle[0].x, curTriangle[0].y),
                 Point(curTriangle[2].x, curTriangle[2].y), GREEN, 2);
                 
                 line(hey, Point(curTriangle[0].x, curTriangle[0].y),
                 Point(curTriangle[1].x, curTriangle[1].y), GREEN, 2);
                 
                 line(hey, Point(curTriangle[1].x, curTriangle[1].y),
                 Point(curTriangle[2].x, curTriangle[2].y), GREEN, 2);
                 imshow("hello", hey);
                 waitKey();
            }//*/
            return k;
        }
    }
    return -1;
}
Example #3
0
int main() {
int a;
int b;
int c;
int valid;
int type;
int num;

	num = sanitizedInput();
	a = num;
	num = sanitizedInput();
	b = num;
	num = sanitizedInput();
	c = num;
	valid = isTriangle(a, b, c);
	type = triangleType(a, b, c);
	if (valid == 0) {
		printf("Your triangle is not valid!\n");}
	if (valid == 1) {
		printf("Your triangle is valid!\n");}
	if (type == 1) {
		printf("Your triangle is equilateral!\n");}
	if (type == 2) {
		printf("Your triangle is isoceles!\n");}
	if (type == 3) {
		printf("Your triangle is scalene!\n");}
return 0;
}
int main(){
	std::vector<int> triangle_nums;
	for(int i = 0; i < 20; i++)	triangle_nums.push_back( 0.5 * (i * i + i ) );
	std::string temp;
	std::ifstream file ("words.txt");
	unsigned int sum = 0;
	while ( getline( file , temp , ',' ) )	if( isTriangle( scoreword ( temp ) , triangle_nums ))	sum++;
	std::cout<< sum <<std::endl;
	return 0;
} 
Example #5
0
double areaOfTriangle(double a, double b, double c)
{
    if (!isTriangle(a, b, c))
    {
        return 0;
    }

    double p = (a + b + c) / 2;

    return sqrt(p * (p - a) * (p - b) * (p - c));
}
Example #6
0
int main() {
	int triangulartype;
	int extra;
	int sidespicyboys;
	int sidekazookid;
	int sidepepe;
	int invalid;
	sidespicyboys = sanitizedInput();
	sidekazookid = sanitizedInput();
	sidepepe = sanitizedInput();
	extra = isTriangle(sidespicyboys, sidekazookid, sidepepe);	
	triangulartype = triangleType(sidespicyboys, sidekazookid, sidepepe);		
	return 0;
}
Example #7
0
void RS_Solid::draw(RS_Painter* painter, RS_GraphicView* view,
        double& /*patternOffset*/) {

    if (painter==NULL || view==NULL) {
        return;
    }

    RS_SolidData d = getData();
    if (isTriangle()) {
        painter->fillTriangle(view->toGui(getCorner(0)),
                              view->toGui(getCorner(1)),
                              view->toGui(getCorner(2)));
    }

}
Example #8
0
/**
 * @todo Implement this.
 */
RS_Vector RS_Solid::getNearestPointOnEntity(const RS_Vector& coord,
                                            bool onEntity /*= true*/,
                                            double* dist /*= nullptr*/,
                                            RS_Entity** entity /*= nullptr*/) const
{
    //first check if point is inside solid
    bool s1 {sign(data.corner[0], data.corner[1], coord)};
    bool s2 {sign(data.corner[1], data.corner[2], coord)};
    bool s3 {sign(data.corner[2], data.corner[0], coord)};

    if ((s1 == s2) && (s2 == s3)) {
        setDistPtr( dist, 0.0);
        return coord;
    }

    if (!isTriangle()) {
        s1 = sign(data.corner[0], data.corner[2], coord);
        s2 = sign(data.corner[2], data.corner[3], coord);
        s3 = sign(data.corner[3], data.corner[0], coord);
        if ((s1 == s2) && (s2 == s3)) {
            setDistPtr( dist, 0.0);
            return coord;
        }
    }

    // not inside of solid
    // Find nearest distance from each edge
    if (nullptr != entity) {
        *entity = const_cast<RS_Solid*>(this);
    }

    RS_Vector ret(false);
    double currDist {RS_MAXDOUBLE};
    double tmpDist {0.0};
    int totalV {isTriangle() ? RS_SolidData::Triangle : RS_SolidData::MaxCorners};
    for (int i = RS_SolidData::FirstCorner, next = i + 1; i <= totalV; ++i, ++next) {
        //closing edge
        if (next == totalV) {
            next = RS_SolidData::FirstCorner;
        }

        RS_Vector direction {data.corner[next] - data.corner[i]};
        RS_Vector vpc {coord-data.corner[i]};
        double a {direction.squared()};
        if( a < RS_TOLERANCE2) {
            //line too short
            vpc = data.corner[i];
        }
        else{
            //find projection on line
            vpc = data.corner[i] + direction * RS_Vector::dotP( vpc, direction) / a;
        }
        tmpDist = vpc.distanceTo( coord);
        if (tmpDist < currDist) {
            currDist = tmpDist;
            ret = vpc;
        }
    }

    //verify this part
    if (onEntity && !ret.isInWindowOrdered( minV, maxV)) {
        // projection point not within range, find the nearest endpoint
        ret = getNearestEndpoint( coord, dist);
        currDist = ret.distanceTo( coord);
    }

    setDistPtr( dist, currDist);

    return ret;
}
Example #9
0
bool RS_Solid::isInCrossWindow(const RS_Vector& v1, const RS_Vector& v2) const
{
    RS_Vector vBL;
    RS_Vector vTR;
    RS_VectorSolutions sol;

    //sort input vectors to BottomLeft & TopRight
    if (v1.x < v2.x) {
        vBL.x = v1.x;
        vTR.x = v2.x;
    }
    else {
        vBL.x = v2.x;
        vTR.x = v1.x;
    }
    if (v1.y < v2.y) {
        vBL.y = v1.y;
        vTR.y = v2.y;
    }
    else {
        vBL.y = v2.y;
        vTR.y = v1.y;
    }

    //Check if entity is out of window
    if (getMin().x > vTR.x
        || getMax().x < vBL.x
        || getMin().y > vTR.y
        || getMax().y < vBL.y) {
        return false;
    }

    std::vector<RS_Line> border;
    border.emplace_back( data.corner[0], data.corner[1]);
    border.emplace_back( data.corner[1], data.corner[2]);
    if (isTriangle()) {
        border.emplace_back( data.corner[2], data.corner[0]);
    }
    else {
        border.emplace_back( data.corner[2], data.corner[3]);
        border.emplace_back( data.corner[3], data.corner[0]);
    }

    //Find crossing edge
    if (getMax().x > vBL.x
        && getMin().x < vBL.x) {    //left
        RS_Line edge {vBL, {vBL.x, vTR.y}};
        for (auto const& line: border) {
            sol = RS_Information::getIntersection(&edge, &line, true);
            if (sol.hasValid()) {
                return true;
            }
        }
    }
    if (getMax().x > vTR.x
        && getMin().x < vTR.x) {    //right
        RS_Line edge {{vTR.x, vBL.y}, vTR};
        for (auto const& line: border) {
            sol = RS_Information::getIntersection(&edge, &line, true);
            if (sol.hasValid()) {
                return true;
            }
        }
    }
    if (getMax().y > vBL.y
        && getMin().y < vBL.y) {    //bottom
        RS_Line edge {vBL, {vTR.x, vBL.y}};
        for(auto const& line: border) {
            sol = RS_Information::getIntersection(&edge, &line, true);
            if (sol.hasValid()) {
                return true;
            }
        }
    }
    if(getMax().y > vTR.y
       && getMin().y < vTR.y) { //top
        RS_Line edge {{vBL.x, vTR.y}, vTR};
        for(auto const& line: border) {
            sol = RS_Information::getIntersection(&edge, &line, true);
            if (sol.hasValid()) {
                return true;
            }
        }
    }

    return false;
}