第一章 课程信息

本课件链接: https://elonzyy.github.io/course-skp19

Github链接: https://github.com/elonzyy/course-skp19

环境配置

下载并安装 SketchUp

下载链接: https://www.sketchup.com/zh-CN/download/all

2017 Make 是免费版,但不可用于商业通途。

2017-2019 都适用于本课程。

选择并安装一款代码编辑器

关于Ruby解释器

本课程只会用到SketchUp自带的Ruby解释器。并不需要额外下载并安装Ruby。

如果同学有兴趣在非SketchUp的环境下运行ruby文件可以安装独立的Ruby解释器。

下载链接: https://www.ruby-lang.org/en/downloads

也可以使用RVM安装Ruby解释器,链接: https://rvm.io

参考文档

Ruby文档: https://ruby-doc.org

SketchUp Ruby API文档:http://ruby.sketchup.com

第二章 Ruby基础

第三章 几何

工具箱

代码链接:op_course_helpers/visualization/pt_and_vec.rb

可视化 Geom::Point3d

CourseHelpers.visualize_pt(Geom::Point3d.new([1.m, 1.m, 0]))

可视化 Geom::Vector3d

CourseHelpers.visualize_vec(Geom::Vector3d.new([1.m, 1.m, 1.m]))

长度 Length

API文档: http://ruby.sketchup.com/Length.html

从数值类型创建长度

100.to_l
100.mm

从字符串类型创建长度

'100mm'.to_l
Sketchup.parse_length('100mm')

SketchUp 单位

  • mm
  • cm
  • m
  • km
  • inch (")
  • feet (')
  • yard
  • mile

长度单位换算

  • 数值类型默认单位:inch
100.mm.to_inch

API

关键字描述文档链接
Length长度类型doc
to_l转换至长度doc
parse_length将字符串转换至长度doc
mm从数值创建单位为mm的长度doc
cm从数值创建单位为cm的长度doc
m从数值创建单位为m的长度doc
km从数值创建单位为km的长度doc
inch从数值创建单位为inch的长度doc
feet从数值创建单位为feet的长度doc
yard从数值创建单位为yard的长度doc
mile从数值创建单位为mile的长度doc
to_mm将长度转换为数值,数值意义所隐含的单位为mmdoc
to_cm将长度转换为数值,数值意义所隐含的单位为cmdoc
to_m将长度转换为数值,数值意义所隐含的单位为mdoc
to_km将长度转换为数值,数值意义所隐含的单位为kmdoc
to_inch将长度转换为数值,数值意义所隐含的单位为inchdoc
to_feet将长度转换为数值,数值意义所隐含的单位为feetdoc
to_yard将长度转换为数值,数值意义所隐含的单位为yarddoc
to_mile将长度转换为数值,数值意义所隐含的单位为miledoc

笛卡尔坐标系、点

笛卡尔坐标系

  • 红(X)、绿(Y)、蓝(Z)
  • 互相垂直
  • 交于原点

右手定则

创建Point3d

[2.m, 1.m, 0]
Geom::Point3d.new(2.m, 1.m, 0)

原点常量

ORIGIN

判断位置相同

Geom::Point3d.new(2.m, 1.m, 0) == [2.m, 1.m, 0]

Ruby语言运算符是方法

'string1'.eql?('string2')
'string1'.==('string2')
'string1' == 'string2'

点与点的距离

公式

distance

ORIGIN.distance(Geom::Point3d.new(2.m, 1.m, 0))

API

关键字描述文档链接
Point3d点类型doc
ORIGIN原点常量doc
point3d.x获取x分量doc
point3d.y获取y分量doc
point3d.z获取z分量doc
array.x获取数组第一个元素doc
array.y获取数组第二个元素doc
array.z获取数组第三个元素doc
point3d.==判断位置是否相同doc
distance两点之间距离doc

练习题

  1. 使用 is_a? 判断以下命题是否正确:
  • 0.2 是 Float
  • -10 是 Integer
  • Float::INFINITY 是 Numeric
  • 'text' 是 Numeric
  • nil 是 Object
  1. 小明在美国开车行驶速度为 80km/h,路边交通表示显示限速为 50(miles/h) 请问小明是否超速。

  2. 多选:下列坐标系哪些是符合右手定则的笛卡尔坐标系(右手坐标系)?

A
B
C
D

版权信息

Author: elonzyy

License: CC BY-SA 4.0

The mdbook files, and associated images and figures in directories book-src/ are licensed under Creative Commons Attribution-ShareAlike 4.0 International License (cc by-sa).

图片引用列表

  • https://commons.wikimedia.org/wiki/File:Right_hand_rule_cross_product.svg