用什么函数画矩形

用什么函数画矩形,第1张

没有专门的矩形函数吧。好像只能用画线函数来实现画矩形。

thislinestyle(1,

0xff0000,

100);

thisbeginfill(0x0000ff,

100);

thismoveto(200,

200);

thislineto(400,

200);

thislineto(400,

300);

thislineto(200,

300);

thislineto(200,

200);

这就是画一个矩形的脚本,并填充了蓝色。

(defun c:tes ( / &k1 &kw1 &ss1 i)

 (vl-load-com)

 (princ "\n请选择对象")

 (if (setq &kw1 (ssget))

  (progn

   (setq &ss1 '() i -10)

   (while (setq &k1 (ssname &kw1 (setq i (1+ i))))

    (setq &ss1 (cons &k1 &ss1))

   );while

   (setq &ss1 (a1611192 &ss1));对角点

   (entmake (list '(0  "CIRCLE") (cons 10 (car &ss1)) '(40  100)))

   (entmake (list '(0  "CIRCLE") (cons 10 (cadr &ss1)) '(40  100)));测试点位置

  )

 )

 (princ)

)

;函数功能:获取最大包围框:输入由图元构成的表

(defun a1611192 (lst / lst)

 (setq lst (mapcar 'a1611191 (mapcar 'vlax-ename->vla-object lst)))

 (list

  (list 

       (car (vl-sort (mapcar 'caar lst) '<))

       (car (vl-sort (mapcar 'cadar lst) '<)))

 (list 

      (car (vl-sort (mapcar 'caadr lst) '>))

      (car (vl-sort (mapcar 'cadadr lst) '>))

 ))

)

(defun a1611191 (obj / x y)

 (vla-getboundingbox obj 'x 'y)

 (mapcar 'vlax-safearray->list (list x y))

)

autolisp程序获取最大包围框。

Rectangle a = new Rectangle(2,2)是在实例化一个Rectangle对象

那么他调用的是Rectangle类的构造函数。

但是你自己写的Rectangle类没有自己实现构造函数,所以它只有一个无参的构造函数(所有的类在C#里面会有一个无参的构造函数)。那么你调用Rectangle a = new Rectangle()是可以编译通过的。

但是如果你希望在实例化的时候就能设置矩形的长宽的话,你需要自己在Rectangle里面自己实现一个带两个参数的构造函数:

public Rectangle(int x, int y)

{

thisx=x;

thisy=y;

}

这样在初始化这个矩形对象的时候也可以初始化它的长宽。

但是这个时候隐式的那个无参的构造函数将会破坏掉。这是后话,跟这个问题没什么关系了。

不知道我解释清楚没有。

请参见注释

using System;

using SystemCollectionsGeneric;

using SystemText;

namespace ConsoleApp03

{

class Program

{

static void Main(string[] args)

{

// 实例化矩形a

Rectangle a = new Rectangle(2,2);

// 实例化矩形b

Rectangle b = new Rectangle(3,3);

// 矩形a与矩形b相加(后面重载了 *** 作符‘+’)

ConsoleWriteLine(a+b);

}

}

//矩形类

class Rectangle

{

// x,y分别代表长,宽

public int x;

public int y;

public Rectangle(int x, int y)

{

thisx=x;

thisy=y;

}

public int X

{

get {return x;}

set { thisx = value; }

}

public int Y

{

get { return y; }

set { thisy = value; }

}

// 这里重载 *** 作符号‘+’,上面的主函数为什么能够两个矩形//相加就是因为这个原因。

//这里这个+号的意义变成了两个矩形的面积和。

public static double operator +(Rectangle R1, Rectangle R2)

{

return R1X R1Y + R2X R2Y;

}

}

}

#include<iostream>

using namespace std;

class Rectangle{

private:

double width,height;

public:

double getwidth() {

return width;

}

public:

void setLength(double width) { //名字还是统一为setWidth比较好

thiswidth = width; // this是指针,下同

}

double getheight() {

return height;

}

void setheight(double width) {

thisheight =height;

}

Rectangle() { }

Rectangle(double height, double width) {

thisheight = height;

thiswidth = width;

}

double getArea(){

return heightwidth;

}

double getPerimeter(){

return 2(height+width);

}

public:

static

void main(int argc, char argv[]) { //static定义是没有必要的

double a,b;

cin>>a>>b;

Rectangle rectangle=new Rectangle(a,b);

cout<<"矩形面积是:"+rectanglegetArea()<<endl; //输出有问题吧

cout<<"矩形周长是:"+rectanglegetPerimeter()<<endl;

return 0;

}

解决建议,设立变量来保存矩形面积和周长,设立函数来计算,然后在各种函数里调用set更新,main则调用get获取

以上就是关于用什么函数画矩形全部的内容,包括:用什么函数画矩形、lisp 中如何获取选中对象的最大外框矩形、用函数定义和调用的方法求矩形的面积。+(长宽为整数,从键盘输入)等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9553990.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-29
下一篇2023-04-29

发表评论

登录后才能评论

评论列表(0条)

    保存