当前位置: 首页>>代码示例>>C++>>正文


C++ line类代码示例

本文整理汇总了C++中line的典型用法代码示例。如果您正苦于以下问题:C++ line类的具体用法?C++ line怎么用?C++ line使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了line类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: line_line

const collision line_line(const line &a, const line &b)
{
	collision r;

	auto m1 = (a.position.y - a.end.y) / (a.position.x - a.end.x);
	auto m2 = (b.position.y - b.end.y) / (b.position.x - b.end.x);

	auto b1 = a.position.y - m1*a.position.x;
	auto b2 = b.position.y - m2*b.position.x;

	float x = (b2 - b1) / (m1 - m2);
	float y = m1*x + b1;

	if ((a.position.x - a.end.x) == 0) // if a is a vertical line, then there is only 1 possible x value.
	{	x = a.position.x;	y = m2 *x + b2;	}
	if ((b.position.x - b.end.x) == 0)
	{	x = b.position.x;	y = m1 *x + b1;	}

	r.contact = { x, y }; point p(r.contact);
	r.result = circle_point(circle(a.mid(), a.length() / 2), p).result
		    && circle_point(circle(b.mid(), b.length() / 2), p).result;

	if (m1 == m2)
	{
		r.result = false;
		return r;
	}
	return r;
}
开发者ID:Zac-King,项目名称:GameAI,代码行数:29,代码来源:shapes.cpp

示例2: intersec

int intersec(const line& l1, const line& l2,
             point& res){
  assert(!(l1.v == point()));
  assert(!(l2.v == point()));
  if (vp(l1.v,l2.v) == point()){
    if (vp(l1.v, l1.p - l2.p) == point())
      return 2; // same
    return 0; // parallel
  }
  point n = vp(l1.v,l2.v);
  point p = l2.p - l1.p;
  if (sgn(sp(n,p)))
    return 0; // skew
  ld t;
  if (sgn(n.x))
    t = (p.y * l2.v.z - p.z * l2.v.y) / n.x;
  else if (sgn(n.y))
    t = (p.z * l2.v.x - p.x * l2.v.z) / n.y;
  else if (sgn(n.z))
    t = (p.x * l2.v.y - p.y * l2.v.x) / n.z;
  else
    assert(false);
  res = l1.p + l1.v * t;
  assert(l1.on(res)); assert(l2.on(res));
  return 1; // intersects
}
开发者ID:kunyavskiy,项目名称:SPbSU4-Team-Notebook,代码行数:26,代码来源:geom-3d.cpp

示例3: make_tuple

std::tuple<bool, float> line::intersect(const line &other) const {

    //from http://stackoverflow.com/a/1968345
    double p0_x = m_origin.x();
    double p0_y = m_origin.y();
    double p1_x = m_target.x();
    double p1_y = m_target.y();
    double p2_x = other.origin().x();
    double p2_y = other.origin().y();
    double p3_x = other.target().x();
    double p3_y = other.target().y();

    double s1_x = p1_x - p0_x;
    double s1_y = p1_y - p0_y;
    double s2_x = p3_x - p2_x;
    double s2_y = p3_y - p2_y;

    if ((-s2_x * s1_y + s1_x * s2_y) == 0) {
        return std::make_tuple(false, 0.0f);
    }

    double s = (-s1_y * (p0_x - p2_x) + s1_x * (p0_y - p2_y)) / (-s2_x * s1_y + s1_x * s2_y);
    double t = ( s2_x * (p0_y - p2_y) - s2_y * (p0_x - p2_x)) / (-s2_x * s1_y + s1_x * s2_y);

    double w = 0.1;
    if (s >= 0-w && s <= 1+w && t >= 0-w && t <= 1+w)
    {
        // Collision detected
        return std::make_tuple(true, t);
    }
    return std::make_tuple(false, 0.0f);
}
开发者ID:mohlek,项目名称:game-of-life,代码行数:32,代码来源:line.cpp

示例4: isInPlane

	bool plane::isInPlane(const line& l)const
	{
		auto dot = norm_.dotProduct(l.dir());
		if (!floatEqual(dot, 0.0f))
			return false;

		return isInPlane(l.start());
	}
开发者ID:zouxiaohang,项目名称:zengine,代码行数:8,代码来源:plane.cpp

示例5: intersect

point intersect(line & l, segment s) {
    double da = fabs(l.dist(s.a)), db = fabs(l.dist(s.b));
    if (da + db < eps) {
        return s.a;
    } else {
        double t = da / (da + db);
        return s.a + (s.b - s.a) * t;
    }
}
开发者ID:AVBelyy,项目名称:CompGeometry,代码行数:9,代码来源:hp-intersection-nlogm.cpp

示例6: draw_line

      void draw_line ( line l )
	{
	  XDrawLine ( m_display,
		      m_window_id,
		      m_gc,
		      l.point1().x(),
		      l.point1().y(),
		      l.point2().x(),
		      l.point2().y() );
	}
开发者ID:8l,项目名称:x11,代码行数:10,代码来源:graphics_context.hpp

示例7:

	std::pair<bool, vector3> plane::intersection(const line& l)const
	{
		auto ret = std::make_pair<bool, vector3>(false, vector3());
		if (isInPlane(l))
			return ret;

		ret.first = true;
		auto t = (norm_.dotProduct(point_) - norm_.dotProduct(l.start())) / (norm_.dotProduct(l.dir()));
		ret.second = l.start() + t * l.dir();
		return ret;
	}
开发者ID:zouxiaohang,项目名称:zengine,代码行数:11,代码来源:plane.cpp

示例8: res

pt operator&(const line &l1, const line &l2) {
  double d = l1.a * l2.b - l1.b * l2.a;
  assert(fabs(d) > eps);
  pt res(
    (l1.b * l2.c - l1.c * l2.b) / d,
    (l1.a * l2.c - l1.c * l2.a) / -d
  );
  assert(l1.side(res) == 0);
  assert(l2.side(res) == 0);
  return res;
}
开发者ID:kunyavskiy,项目名称:SPbSU4-Team-Notebook,代码行数:11,代码来源:geom-double.cpp

示例9: intersection

    // gets the intersection between two lines (not segments)
    // ot : the other line
    // if they are equal, returns nan
    // if they are parallel, returns inf
    // else, returns the x on which the intersection occurs
    double intersection (const line<cood> & ot) const {
        double a[2] = {slope(), ot.slope()};
        double b[2] = {intercept(a[0]), ot.intercept(a[1])};

        if (abs(a[0]-a[1]) < eps) {
            if (abs(b[0]-b[1]) < eps) return 0./0.;
            return 1./0.;
        } else {
            debug("%.2f/%.2f", b[0]-b[1], a[1]-a[0]);
            return (b[0]-b[1])/(a[1]-a[0]);
        }
        
        return true;
    }
开发者ID:victorsenam,项目名称:treinos,代码行数:19,代码来源:old.cpp

示例10: assert

    const double
    line::getDistFromLine(const line& l) const
    {
        assert(this->is_Set() && l.is_Set());
        double this_ori = this->getOrientation();
        double other_ori = l.getOrientation();
        double diff_ori = fabs(this_ori - other_ori);

        double d = (point2Line(*this, l.m_endp1) <= point2Line(*this, l.m_endp2)) ?
                point2Line(*this, l.m_endp1): point2Line(*this, l.m_endp2);

        return d + 1.5*diff_ori; // 1.5 is a magic number

        return 0;
    }
开发者ID:91yuan,项目名称:simple_lane_tracking,代码行数:15,代码来源:line.cpp

示例11: overlap

	bool overlap(line another){
		if(type !=another.type){
			return false;
		}
		if(type==0){
			if (y0!=another.y0){
				return false;
			}
		}
		if(type==1){
			if (x0!=another.x0){
				return false;
			}
		}
		if(type==2 ){
			if (y0-x0!=another.y0-another.x0){
				return false;
			}
		}
		if(type==3 ){
			if (y0+x0!=another.y0+another.x0){
				return false;
			}
		}
		line possible_merge_line=merge(another);
		if(possible_merge_line.len()<=len()+another.len()){
			return true;
		}
		return false;
	}
开发者ID:shijiaxin,项目名称:algorithm,代码行数:30,代码来源:old_wangyi_3.cpp

示例12: main

int main () {
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        debug("%d: ", i);
        scanf("%lld %lld", &v.s.x, &v.s.y);
        scanf("%lld %lld", &v.t.x, &v.t.y);

        scanf("%lld %lld", &a[0].x, &a[0].y);
        scanf("%lld %lld", &a[2].x, &a[2].y);

        a[1].x = a[0].x;
        a[1].y = a[2].y;

        a[3].x = a[2].x;
        a[3].y = a[0].y;

        if (v.s.inside({a[0], a[1], a[2], a[3]}) || v.t.inside({a[0], a[1], a[2], a[3]})) {
            debug("1");
            printf("T\n");
            continue;
        }

        int j = 0;
        for (j = 0; j < 4; j++) {
            line<> u(a[j], a[(j+1)%4]);

            double x = v.intersection(u);
            if (x == 0./0.) {
                debug("e");
                if (v.contains(u.s.x) || v.contains(u.t.x) || u.contains(v.s.x) || u.contains(v.t.x))
                    break;
            } else if (v.contains(x) && u.contains(x)) {
                debug("c");
                break;
            } else {
                debug("[%.1f]", x);
            }
        }

        if (j == 4) 
            printf("F\n");
        else
            printf("T\n");
    }
}
开发者ID:victorsenam,项目名称:treinos,代码行数:46,代码来源:old.cpp

示例13: drawLine

void drawLine(line l) {
    if (l.isDiameter()) {
        glBegin(GL_LINE_STRIP);
        glVertex2d(l.getLeft().getX(), l.getLeft().getY());
        glVertex2d(l.getRight().getX(), l.getRight().getY());
        glEnd();
        return;
    }
    double middle = l.getCenter().arg() + M_PI;
    double deflection = atan(1/l.getRadius());
    double start = middle - deflection;
    double end = middle + deflection;
    drawArc(l.getCenter(), l.getRadius(), start, end);
}
开发者ID:shsty,项目名称:Geometry,代码行数:14,代码来源:draw.cpp

示例14: check_cross

void check_cross(const pt &cent, const double &r, const line &l, int need_cnt) {
  vector<pt> res = cross(cent, r, l);
  printf("check circle&line\n");
  for (int i = 0; i < sz(res); i++) {
    printf("  %.2lf %.2lf\n", res[i].x, res[i].y);
    assert(l.side(res[i]) == 0);
    assert(fabs((cent - res[i]).dist2() - r * r) < eps);
  }
  assert(sz(res) == need_cnt);
}
开发者ID:kunyavskiy,项目名称:SPbSU4-Team-Notebook,代码行数:10,代码来源:geom-double.cpp

示例15: cross

vector<pt> cross(const pt &center, double r,
                 const line &l) {
  double di = l.distz(center);
  double d2 = l.norm2();
  assert(fabs(d2) > eps);
  pt mid = center + pt(l.a, l.b) * (-di / d2);
  #ifdef DEBUG
  assert(l.side(mid) == 0);
  #endif

  double s = r * r - di * di / d2;
  if (s < -eps) return vector<pt>();
  if (fabs(di * di - r * r * d2) < eps)
    return vector<pt>(1, mid);

  pt off = pt(-l.b, l.a) * sqrt(s / d2);
  assert(fabs(off.dist2() - s) < eps);
  vector<pt> res;
  res.pb(mid + off);
  res.pb(mid - off);
  return res;
}
开发者ID:kunyavskiy,项目名称:SPbSU4-Team-Notebook,代码行数:22,代码来源:geom-double.cpp


注:本文中的line类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。