LiteCAD参考文档的学习三(图形对象之点、构造线(射线)、线段、角度、折线、长方形、圆、圆弧、椭圆)

LiteCAD API reference

一、Point

The point’s appearance depends on the drawing’s properties
LC_PROP_DRW_PDMODE and LC_PROP_DRW_PDSIZE
在这里插入图片描述
在这里插入图片描述
To add points into a drawing use following functions:lcBlockAddPoint;lcBlockAddPoint2;lcBlockAddPoint3d

Points buffer
Points buffer is a list of points that represent geometric shape. It can be drawn in a window with the function lcPaint_DrawPtbuf .

二、Construction Line (and Ray)

Lines that extend to infinity in one or both directions, known as rays and construction lines, respectively, can be used as references for creating other objects. For example, you can use construction lines to find the center of a triangle, prepare multiple views of the same item, or create temporary intersections to use for object snaps.
在这里插入图片描述
To add construction lines and rays into a drawing use following functions:lcBlockAddXline;lcBlockAddXline2P.
Type specific functions:lcXlinePutDir.

三、Line

A single line segment having two endpoints only. Lines can be one segment or a series of connected segments, but each segment is a separate line object. Use the line object if you want to edit individual segments. If you need to draw a series of line segments as a single object, use the Polyline object.

Create tangent lines

void DemoTangLines (HANDLE hLcWnd)
{
  HANDLE hDrw, hBlock, hEnt1, hEnt2, hEnt3, hLayer1, hLayer2;
  WCHAR* szName1 = L"Circles";
  WCHAR* szName2 = L"Tangent Lines";

  // get drawing and block, linked with CAD window
  hDrw = lcPropGetHandle( hLcWnd, LC_PROP_WND_DRW );
  hBlock = lcPropGetHandle( hLcWnd, LC_PROP_WND_VIEWBLOCK );
  // layer for circles
  hLayer1 = lcDrwGetObjectByName( hDrw, LC_OBJ_LAYER, szName1 );
  if (hLayer1 == 0){
    // create the layer
    hLayer1 = lcDrwAddLayer( hDrw, szName1, L"foreground", 0, LC_LWIDTH_DEFAULT );
  }
  // layer for lines
  hLayer2 = lcDrwGetObjectByName( hDrw, LC_OBJ_LAYER, szName2 );
  if (hLayer2 == 0){
    // create the layer
    hLayer2 = lcDrwAddLayer( hDrw, szName2, L"255,0,0", 0, LC_LWIDTH_DEFAULT );
  }
  // set active layer
  lcPropPutHandle( hDrw, LC_PROP_DRW_LAYER, hLayer1 );  
  // add circles
  hEnt1 = lcBlockAddCircle( hBlock, 0, 0, 10, LC_FALSE );
  hEnt2 = lcBlockAddCircle( hBlock, 20, 20, 15, LC_FALSE );
  hEnt3 = lcBlockAddCircle( hBlock, 28, -10, 7, LC_FALSE );
  // set active layer
  lcPropPutHandle( hDrw, LC_PROP_DRW_LAYER, hLayer2 );
  // add tangent lines
  lcBlockAddLineTan( hBlock, hEnt1, hEnt2, 0 );
  lcBlockAddLineTan( hBlock, hEnt1, hEnt2, 1 );
  lcBlockAddLineTan( hBlock, hEnt1, hEnt3, 2 );
  lcBlockAddLineTan( hBlock, hEnt2, hEnt3, 3 );
  // display
  lcBlockUpdate( hBlock, true, 0 );
  lcWndExeCommand( hLcWnd, LC_CMD_ZOOM_EXT, 0 );
}

在这里插入图片描述

四、Angles

In API functions and object properties, angle is specified in radians, counter-clockwise from 0-X axis.
LC_RAD_TO_DEG: 57.2957795130823208 Coefficient for converting radians to degrees.
LC_DEG_TO_RAD: 0.0174532925199433 Coefficient for converting degrees to radians.

五、Polyline

A polyline is a connected sequence of line or arc segments created as a single object. Use polylines if you want to edit all segments at once (although you can also edit them singly). You can apply various Fit types to polylines and close the polyline to form a polygon.
Closed polylines can be filled with solid color. LiteCAD treats such objects as polygons and the user can select them by clicking inside of their boundary(s).
Create polylines

void DemoPolylines (HANDLE hLcWnd)
{
  HANDLE hBlock;
  HANDLE hPline, hPline2, hPline3, hPline4, hPline5;

  // get the block linked to graphics window
  hBlock = lcPropGetHandle( hLcWnd, LC_PROP_WND_VIEWBLOCK );
  // add a polyline object
  hPline = lcBlockAddPolyline( hBlock, 0, false, false );
  lcPlineAddVer( hPline, 0, 10, 0 );
  lcPlineAddVer( hPline, 0, 20, 10 );
  lcPlineAddVer( hPline, 0, 30, 0 );
  lcPlineAddVer( hPline, 0, 40, 10 );
  lcPlineAddVer( hPline, 0, 50, 0 );
  lcPlineAddVer( hPline, 0, 60, 10 );
  lcPlineAddVer( hPline, 0, 70, 0 );
  lcPlineEnd( hPline );
  // copy and move the polyline
  lcBlockSelectEnt( hBlock, hPline, true );
  lcBlockSelMove( hBlock, 0, 20, true, false );
  hPline2 = lcBlockGetLastEnt( hBlock );
  lcBlockSelMove( hBlock, 0, 40, true, false );
  hPline3 = lcBlockGetLastEnt( hBlock );
  lcBlockSelMove( hBlock, 0, 60, true, false );
  hPline4 = lcBlockGetLastEnt( hBlock );
  lcBlockSelMove( hBlock, 0, 80, true, false );
  hPline5 = lcBlockGetLastEnt( hBlock );
  lcBlockUnselect( hBlock );
  // modify fit type of the copied polylines
  lcPropPutInt( hPline2, LC_PROP_PLINE_FIT, LC_PLFIT_QUAD );
  lcPropPutInt( hPline3, LC_PROP_PLINE_FIT, LC_PLFIT_CUBIC );
  lcPropPutInt( hPline4, LC_PROP_PLINE_FIT, LC_PLFIT_SPLINE );
  lcPropPutInt( hPline5, LC_PROP_PLINE_FIT, LC_PLFIT_ROUND );
  lcPropPutFloat( hPline5, LC_PROP_PLINE_RADIUS, 2.5 );

  lcBlockUpdate( hBlock, true, 0 );
  lcWndExeCommand( hLcWnd, LC_CMD_ZOOM_EXT, 0 );
}

在这里插入图片描述
Create a closed polylines with filling

void DemoFilling (HANDLE hLcWnd)
{
  HANDLE hDrw, hBlock, hEnt, hEnt2, hFill, hFill2;
  WCHAR* szNameFill = L"Hatch 1";
  WCHAR* szNameFill2 = L"Hatch 2";
  
  // get a drawing and a block, linked with CAD window
  hDrw = lcPropGetHandle( hLcWnd, LC_PROP_WND_DRW );
  hBlock = lcPropGetHandle( hLcWnd, LC_PROP_WND_BLOCK );

  // check if the filling style with specific name already exist
  hFill = lcDrwGetObjectByName( hDrw, LC_OBJ_FILLING, szNameFill );
  if (hFill == 0){
    // don't exist, add it
    hFill = lcDrwAddFilling( hDrw, szNameFill );
    lcFillSetLine( hFill, 0, 1.0, 0.0, 0.5 );
  }

  // check if the filling style with specific name already exist
  hFill2 = lcDrwGetObjectByName( hDrw, LC_OBJ_FILLING, szNameFill2 );
  if (hFill2 == 0){
    // don't exist, add it
    hFill2 = lcDrwAddFilling( hDrw, szNameFill2 );
    lcFillSetLine( hFill2, 0, 1.8, 45.0*LC_DEG_TO_RAD, 0.5 );
    lcFillSetLine( hFill2, 1, 1.8, -45.0*LC_DEG_TO_RAD, 0.5 );
  }

  // create closed and filled polyline
  // the filling is solid by default
  hEnt = lcBlockAddPolyline( hBlock, LC_PLFIT_NONE, true, true );
  lcPlineAddVer( hEnt, 0, 10,30 ); 
  lcPlineAddVer( hEnt, 0,  8,55 ); 
  lcPlineAddVer( hEnt, 0, 30,70 ); 
  lcPlineAddVer( hEnt, 0, 45,38 ); 
  lcPlineEnd( hEnt );
  // set filling color (red)
  lcPropPutInt( hEnt, LC_PROP_ENT_FCOLORT, RGB(255,0,0) );

  // copy the polyline
  hEnt2 = lcBlockAddClone( hBlock, hEnt );
  // move the copied polyline
  lcEntMove( hEnt2, 40, -10 );
  // set filling color (green)
  lcPropPutInt( hEnt2, LC_PROP_ENT_COLORT, RGB(0,255,0) );
  // set filling style
  lcPropPutHandle( hEnt2, LC_PROP_ENT_FILLING, hFill );

  // copy the polyline
  hEnt2 = lcBlockAddClone( hBlock, hEnt );
  // move the copied polyline
  lcEntMove( hEnt2, 80, 10 );
  // set filling color (cyan)
  lcPropPutInt( hEnt2, LC_PROP_ENT_COLORT, RGB(0,255,255) );
  // set filling style
  lcPropPutHandle( hEnt2, LC_PROP_ENT_FILLING, hFill2 );

  // update view
  lcBlockUpdate( hBlock, LC_TRUE, 0 );
  // zoom extents
  lcWndZoomRect( hLcWnd, 0, 0, 0, 0 );
}

在这里插入图片描述
Create regular polygons

void DemoRPilygons (HANDLE hLcWnd)
{
  HANDLE hDrw, hBlock;
  double X, Y, R, Ang;

  // get drawing and block, linked with CAD window
  hDrw = lcPropGetHandle( hLcWnd, LC_PROP_WND_DRW );
  hBlock = lcPropGetHandle( hLcWnd, LC_PROP_WND_BLOCK );

  X = 10.0;
  Y = 20.0;
  R = 10.0;
  Ang = 90.0 * LC_DEG_TO_RAD;
  lcPropPutInt( hDrw, LC_PROP_DRW_COLORT, RGB(0,100,200) ); 
  lcBlockAddCircle( hBlock, X,Y, R, false );
  lcPropPutInt( hDrw, LC_PROP_DRW_COLORT, RGB(255,150,0) ); 
  lcPropPutInt( hDrw, LC_PROP_DRW_FCOLORT, RGB(20,50,80) ); 
  lcBlockAddRPolygon( hBlock, 6, X,Y, R, Ang, false, false );
  lcBlockAddRPolygon( hBlock, 3, X,Y, R, Ang, true, true );
  lcBlockUpdate( hBlock, true, 0 );
  lcWndZoomRect( hLcWnd, X-R-R, Y-R-R, X+R+R, Y+R+R );
}

在这里插入图片描述
Fit type of polyline
A “Fit type” parameter determines how a polyline’s curve fits to a polyline’s vertices.
LC_PLFIT_BULGE(“Bulge coefficient”);LC_PLFIT_QUAD(Quadratic B-spline);
LC_PLFIT_CUBIC;LC_PLFIT_ROUND;LC_PLFIT_LINQUAD.

Multipolygon
Multipolygon object is a list of polygons. It is used to display filled shapes. It can be drawn in a window with the function lcPaint_DrawMpgon .

六、Rectangle

A rectangle is a quadrilateral shape with four right angles. It can be rotated around its center point.The corners can be smoothed with an arc or chamfer.
To add rectangles into a drawing use following functions:lcBlockAddRect;lcBlockAddRect2.
在这里插入图片描述

七、Circle

To add circles into a drawing use following functions: HANDLE lcBlockAddCircle ( HANDLE hBlock,double X,double Y,double Radius,BOOL bFilled);
在这里插入图片描述

八、Arc

To add arcs into a drawing use following functions:lcBlockAddArc;lcBlockAddArc3P;lcBlockAddFillet;
在这里插入图片描述
Create simple entities

void DemoEntities (HANDLE hLcWnd)
{
  HANDLE hDrw, hBlock;
  double x, y, x2, y2, w, h, ang, ang0, ang2, rad, rad2;

  // get drawing and block, linked with CAD window
  hDrw = lcPropGetHandle( hLcWnd, LC_PROP_WND_DRW );
  hBlock = lcPropGetHandle( hLcWnd, LC_PROP_WND_VIEWBLOCK );
  
  // set active color
  lcPropPutInt( hDrw, LC_PROP_DRW_COLOR, RGB(255,0,0) );

  // add points
  x = 0.0;
  y = 0.0;
  lcBlockAddPoint( hBlock, x, y );
  lcBlockAddPoint( hBlock, x, y+5.0 );
  lcBlockAddPoint( hBlock, x, y+10.0 );

  // add lines
  lcPropPutInt( hDrw, LC_PROP_DRW_COLOR, RGB(0,255,0) );
  x = x + 3.0;
  x2 = x + 10.0;
  y2 = y + 2.0;
  lcBlockAddLine( hBlock, x, y, x2, y2 );
  lcBlockAddLine( hBlock, x, y+5.0, x2, y2+5.0 );
  lcBlockAddLine( hBlock, x, y+10.0, x2, y2+10.0 );

  // add rectangles
  lcPropPutInt( hDrw, LC_PROP_DRW_COLOR, RGB(0,0,255) );
  x = x2 + 7.0;
  y = 0;
  w = 10.0;
  h = 5.0;
  ang = 0.0;
  lcBlockAddRect( hBlock, x, y, w, h, ang, false );
  lcBlockAddRect2( hBlock, x, y, w, h, 1.0, false );
  ang = 30.0 * LC_DEG_TO_RAD;
  lcBlockAddRect( hBlock, x, y+10, w, h, ang, false );

  // add circles
  lcPropPutInt( hDrw, LC_PROP_DRW_COLOR, RGB(255,0,255) );
  rad = 2.0;
  x = x + w + rad;
  y = 10.0;
  lcBlockAddCircle( hBlock, x, y, rad, false );
  lcBlockAddCircle( hBlock, x, y, rad+1.0, false );
  lcBlockAddCircle( hBlock, x, y, rad+2.0, false );

  // add arcs
  lcPropPutInt( hDrw, LC_PROP_DRW_COLOR, RGB(255,255,0) );
  ang0 = 30.0 * LC_DEG_TO_RAD;
  ang = 90.0 * LC_DEG_TO_RAD;
  lcBlockAddArc( hBlock, x, y, rad+3, ang0, ang );
  lcBlockAddArc( hBlock, x, y, rad+4, ang0, -ang );

  // add ellipse
  lcPropPutInt( hDrw, LC_PROP_DRW_COLOR, RGB(0,255,255) );
  x = x + 5.0;
  y = 0.0;
  ang = 0.0;
  rad = 4.0;
  rad2 = rad * 0.5;
  lcBlockAddEllipse( hBlock, x, y, rad, rad2, ang, 0.0, 0.0 );
  ang = 45.0 * LC_DEG_TO_RAD; 
  x = x + 7.0;
  y = y + 7.0;
  lcBlockAddEllipse( hBlock, x, y, rad, rad2, ang, 0.0, 0.0 );

  // add elliptical arcs
  lcPropPutInt( hDrw, LC_PROP_DRW_COLOR, RGB(100,55,200) );
  ang0 = 30.0 * LC_DEG_TO_RAD;
  ang2 = 180.0 * LC_DEG_TO_RAD;
  rad = rad + 1.0;
  lcBlockAddEllipse( hBlock, x, y, rad, rad*0.5, ang, ang0, ang2 );
  rad = rad + 1.0;
  lcBlockAddEllipse( hBlock, x, y, rad, rad*0.5, ang, ang0, -ang2 );

  // display
  lcBlockUpdate( hBlock, true, 0 );
  lcWndExeCommand( hLcWnd, LC_CMD_ZOOM_EXT, 0 );
}

在这里插入图片描述

九、Ellipse

在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
射线法又称“点与多边形判断法”,它的基本思想是从该点向任意方向引一条射线,统计该射线与多边形边交点的个数,如果为奇数,则该点在多边形内,如果为偶数,则该点在多边形外。 用C++实现射线法判断一个点是否在一个图形内的代码如下: ```cpp #include <iostream> #include <vector> using namespace std; struct Point { double x, y; }; // 计算向量叉积 double cross_product(Point a, Point b, Point c) { return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x); } // 判断点是否在多边形内 bool point_in_polygon(Point p, vector<Point>& polygon) { int count = 0; int n = polygon.size(); for (int i = 0; i < n; i++) { Point a = polygon[i]; Point b = polygon[(i + 1) % n]; if (a.y == b.y) continue; if (p.y < min(a.y, b.y)) continue; if (p.y >= max(a.y, b.y)) continue; double x = (p.y - a.y) * (b.x - a.x) / (b.y - a.y) + a.x; if (x > p.x) count++; } return (count % 2 == 1); } int main() { Point p = {1, 1}; vector<Point> polygon = {{0, 0}, {2, 0}, {2, 2}, {0, 2}}; bool result = point_in_polygon(p, polygon); if (result) { cout << "The point is in the polygon." << endl; } else { cout << "The point is not in the polygon." << endl; } return 0; } ``` 这里的 `cross_product()` 函数用于计算向量的叉积,用于判断两条线段是否相交。而 `point_in_polygon()` 函数则是核心函数,用于判断点是否在多边形内。该函数针对每条线段进行判断,如果该线段射线相交,则统计交点的个数。最终,根据交点的个数是奇数还是偶数来返回判断结果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值