# Module: AMS::Geometry

Defined in:
Documentation/ams/geometry.rb

Since:

• 3.3.0

## Class Method Summary collapse

• Transition between multiple colors.

• Compute point on cubic bezier curve.

• Compute slope on cubic bezier curve.

• Calculate edge centre of mass.

• Calculate face centre of mass.

• Cast a continuous ray that intersects with all the entities.

• Cast a continuous ray that intersects with the given entities only.

• Cast a continuous ray that intersects with all but the given entities.

• Normalize the scale of axes of a transformation matrix.

• Scales the matrix so that its fifteenths component is 1.0.

• Get the scale of axes of a transformation matrix.

• Get three non-collinear points from an array of three or more points.

• Get plane normal.

• Get points of a two dimensional circle.

• Get points of a three dimensional circle.

• Get an array of unique points from an array of Point3d objects.

• Intersect ray with a triangle.

• Determine whether a transformation matrix is flipped.

• Determine whether a transformation matrix is uniform.

• Determine whether a particular point in on edge.

• Determine whether a particular point is on face.

• Determine whether a particular point is on triangle.

• Determine whether an array of points lie on the same line.

• Determine whether an array of points lie on the same plane.

• Product two vectors - multiply their components.

• Cast a ray through the model that intersects with the given entities only.

• Cast a ray through the model that intersects with all but the given entities.

• Cast a ray that intersects with non-transparent faces only; a ray that passes through all the transparent faces and stops when hits a solid face.

• Rotate a transformation matrix so that its X-axis aligns with a directing vector.

• Rotate a transformation matrix so that its Y-axis aligns with a directing vector.

• Rotate a transformation matrix so that its Z-axis aligns with a directing vector.

• Rotate vector at a normal.

• Scale matrix axes.

• Scale point.

• Scale vector.

• Set the scale of axes of a transformation matrix.

• Sort an array of points in a counter clockwise direction.

• Transition between two cameras.

• Transition between two colors.

• between 0.0 and 1.0.

• Transition between two points.

• Transition between two transformation matrices.

• Transition between two vectors.

## Class Method Details

### .angle_between_vectors(vector1, vector2) ⇒ Numeric .angle_between_vectors(vector1, vector2, normal) ⇒ Numeric

• .angle_between_vectors(vector1, vector2) ⇒ Numeric

Compute angle between two vectors.

Parameters:

• vector1 (Geom::Vector3d)
• vector2 (Geom::Vector3d)
• .angle_between_vectors(vector1, vector2, normal) ⇒ Numeric

Compute angle between two vectors at a normal.

Parameters:

• vector1 (Geom::Vector3d)
• vector2 (Geom::Vector3d)
• normal (Geom::Vector3d)

The normal to compute against.

Returns:

• (Numeric)

Since:

• 3.5.0

 ``` 79 80``` ```# File 'Documentation/ams/geometry.rb', line 79 def angle_between_vectors(*args) end```

### .blend_colors(colors, ratio) ⇒ Sketchup::Color

Transition between multiple colors.

Parameters:

• colors (Array<Sketchup::Color, String, Array>)

An array of colors to transition between.

• ratio (Numeric)

A value between 0.0 and 1.0.

Returns:

• (Sketchup::Color)

Since:

• 3.5.0

 ``` 300 301``` ```# File 'Documentation/ams/geometry.rb', line 300 def blend_colors(colors, ratio) end```

### .calc_cubic_bezier_point(ratio, p0, p1, p2, p3) ⇒ Geom::Point3d

Compute point on cubic bezier curve.

Parameters:

• ratio (Numeric)

A value between 0.0 and 1.0.

• p0 (Geom::Point3d)

First point origin.

• p1 (Geom::Point3d)

First point target.

• p2 (Geom::Point3d)

Second point target.

• p3 (Geom::Point3d)

Second point origin.

Returns:

• (Geom::Point3d)

Since:

• 3.5.0

 ``` 13 14``` ```# File 'Documentation/ams/geometry.rb', line 13 def calc_cubic_bezier_point(ratio, p0, p1, p2, p3) end```

### .calc_cubic_bezier_slope(ratio, p0, p1, p2, p3) ⇒ Geom::Vector3d

Compute slope on cubic bezier curve.

Parameters:

• ratio (Numeric)

A value between 0.0 and 1.0.

• p0 (Geom::Point3d)

First point origin.

• p1 (Geom::Point3d)

First point target.

• p2 (Geom::Point3d)

Second point target.

• p3 (Geom::Point3d)

Second point origin.

Returns:

• (Geom::Vector3d)

Since:

• 3.5.0

 ``` 24 25``` ```# File 'Documentation/ams/geometry.rb', line 24 def calc_cubic_bezier_slope(ratio, p0, p1, p2, p3) end```

### .calc_edge_centre(edge) ⇒ Geom::Point3d

Calculate edge centre of mass.

Parameters:

• edge (Sketchup::Edge)

Returns:

• (Geom::Point3d)

Since:

• 3.3.0

 ``` 126 127``` ```# File 'Documentation/ams/geometry.rb', line 126 def calc_edge_centre(edge) end```

### .calc_face_centre(face) ⇒ Geom::Point3d

Calculate face centre of mass.

Parameters:

• face (Sketchup::Face)

Returns:

• (Geom::Point3d)

Since:

• 3.3.0

 ``` 132 133``` ```# File 'Documentation/ams/geometry.rb', line 132 def calc_face_centre(face) end```

### .deepray1(point, vector, chg = false) ⇒ Array<Array>

Cast a continuous ray that intersects with all the entities.

Parameters:

• point (Geom::Point3d, Array)

Ray position.

• vector (Geom::Vector3d, Array)

Ray direction.

• chg (Boolean) (defaults to: false)

Whether to consider hidden geometry.

Returns:

• (Array<Array>)

An array of ray results.

Since:

• 3.5.0

 ``` 369 370``` ```# File 'Documentation/ams/geometry.rb', line 369 def deepray1(point, vector, chg = false) end```

### .deepray2(entities, point, vector, chg = false) ⇒ Array<Array>

Cast a continuous ray that intersects with the given entities only.

Parameters:

• entities (Array<Sketchup::Drawingelement>)

An array of entities to include.

• point (Geom::Point3d, Array)

Ray position.

• vector (Geom::Vector3d, Array)

Ray direction.

• chg (Boolean) (defaults to: false)

Whether to consider hidden geometry.

Returns:

• (Array<Array>)

An array of ray results.

Since:

• 3.5.0

 ``` 381 382``` ```# File 'Documentation/ams/geometry.rb', line 381 def deepray2(entities, point, vector, chg = false) end```

### .deepray3(entities, point, vector, chg = false) ⇒ Array<Array>

Cast a continuous ray that intersects with all but the given entities.

Parameters:

• entities (Array<Sketchup::Drawingelement>)

An array of entities to ignore.

• point (Geom::Point3d, Array)

Ray position.

• vector (Geom::Vector3d, Array)

Ray direction.

• chg (Boolean) (defaults to: false)

Whether to consider hidden geometry.

Returns:

• (Array<Array>)

An array of ray results.

Since:

• 3.5.0

 ``` 393 394``` ```# File 'Documentation/ams/geometry.rb', line 393 def deepray3(entities, point, vector, chg = false) end```

### .extract_matrix_scale(transformation) ⇒ Geom::Transformation

Normalize the scale of axes of a transformation matrix.

Parameters:

• transformation (Geom::Transformation, Array<Numeric>)

Returns:

• (Geom::Transformation)

A new, normalize transformation matrix.

Since:

• 3.3.0

 ``` 187 188``` ```# File 'Documentation/ams/geometry.rb', line 187 def extract_matrix_scale(transformation) end```

### .extract_matrix_w_factor(transformation) ⇒ Geom::Transformation

Scales the matrix so that its fifteenths component is 1.0.

Parameters:

• transformation (Geom::Transformation, Array<Numeric>)

Returns:

• (Geom::Transformation)

Since:

• 3.6.0

 ``` 194 195``` ```# File 'Documentation/ams/geometry.rb', line 194 def extract_matrix_w_factor(transformation) end```

### .get_matrix_scale(transformation) ⇒ Geom::Vector3d

Get the scale of axes of a transformation matrix.

Parameters:

• transformation (Geom::Transformation, Array<Numeric>)

Returns:

• (Geom::Vector3d)

A vector representing the scale ratios of the X-axis, Y-axis, and Z-axis.

Since:

• 3.3.0

 ``` 173 174``` ```# File 'Documentation/ams/geometry.rb', line 173 def get_matrix_scale(transformation) end```

### .get_noncollinear_points(points) ⇒ Array<Geom::Point3d>?

Get three non-collinear points from an array of three or more points.

Parameters:

• points (Array<Geom::Point3d>)

Returns:

• (Array<Geom::Point3d>, nil)

An array of three non-collinear points if successful.

Since:

• 3.3.0

 ``` 98 99``` ```# File 'Documentation/ams/geometry.rb', line 98 def get_noncollinear_points(points) end```

### .get_plane_normal(plane) ⇒ Geom::Vector3d

Get plane normal.

Parameters:

• plane (Array<Geom::Point3d>)

An array of three, non-collinear points on the plane.

Returns:

• (Geom::Vector3d)

Since:

• 3.3.0

 ``` 105 106``` ```# File 'Documentation/ams/geometry.rb', line 105 def get_plane_normal(plane) end```

### .get_points_on_circle2d(origin, radius, num_seg = 16, rot_angle = 0.0) ⇒ Array<Geom::Point3d>

Get points of a two dimensional circle.

Parameters:

• origin (Array<Numeric>)
• num_seg (Fixnum) (defaults to: 16)

Number of segments.

• rot_angle (Numeric) (defaults to: 0.0)

Returns:

• (Array<Geom::Point3d>)

An array of points making up the circle.

Since:

• 3.5.0

 ``` 310 311``` ```# File 'Documentation/ams/geometry.rb', line 310 def get_points_on_circle2d(origin, radius, num_seg = 16, rot_angle = 0.0) end```

### .get_points_on_circle3d(origin, normal, radius, num_seg = 16, rot_angle = 0) ⇒ Array<Geom::Point3d>

Get points of a three dimensional circle.

Parameters:

• origin (Array<Numeric>, Geom::Point3d)
• normal (Array<Numeric>, Geom::Vector3d)
• num_seg (Fixnum) (defaults to: 16)

Number of segments.

• rot_angle (Numeric) (defaults to: 0)

Returns:

• (Array<Geom::Point3d>)

An array of points making up the circle.

Since:

• 3.5.0

 ``` 321 322``` ```# File 'Documentation/ams/geometry.rb', line 321 def get_points_on_circle3d(origin, normal, radius, num_seg = 16, rot_angle = 0) end```

### .get_unique_points(points) ⇒ Array<Geom::Point3d>

Get an array of unique points from an array of Point3d objects.

Parameters:

• points (Array<Geom::Point3d>)

Returns:

• (Array<Geom::Point3d>)

Since:

• 3.3.0

 ``` 85 86``` ```# File 'Documentation/ams/geometry.rb', line 85 def get_unique_points(points) end```

### .intersect_ray_triangle(origin, direction, pt1, pt2, pt3) ⇒ Geom::Point3d?

Intersect ray with a triangle.

Parameters:

• origin (Geom::Point3d)

The origin of the ray.

• direction (Geom::Vector3d)

The direction of the ray.

• pt1 (Geom::Point3d)

The first vertex of the triangle.

• pt2 (Geom::Point3d)

The second vertex of the triangle.

• pt3 (Geom::Point3d)

The third vertex of the triangle.

Returns:

• (Geom::Point3d, nil)

• http://www.cs.virginia.edu/~gfx/Courses/2003/ImageSynthesis/papers/Acceleration/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf

Since:

• 3.3.0

 ``` 166 167``` ```# File 'Documentation/ams/geometry.rb', line 166 def intersect_ray_triangle(origin, direction, pt1, pt2, pt3) end```

### .is_matrix_flipped?(transformation) ⇒ Boolean

Determine whether a transformation matrix is flipped.

Parameters:

• transformation (Geom::Transformation, Array<Numeric>)

Returns:

• (Boolean)

Since:

• 3.3.0

 ``` 200 201``` ```# File 'Documentation/ams/geometry.rb', line 200 def is_matrix_flipped?(transformation) end```

### .is_matrix_uniform?(transformation) ⇒ Boolean

Determine whether a transformation matrix is uniform. A uniform transformation matrix has its axes perpendicular to each other.

Parameters:

• transformation (Geom::Transformation, Array<Numeric>)

Returns:

• (Boolean)

Since:

• 3.3.0

 ``` 207 208``` ```# File 'Documentation/ams/geometry.rb', line 207 def is_matrix_uniform?(transformation) end```

### .is_point_on_edge?(point, edge) ⇒ Boolean

Determine whether a particular point in on edge.

Parameters:

• point (Geom::Point3d)
• edge (Sketchup::Edge)

Returns:

• (Boolean)

Since:

• 3.3.0

 ``` 139 140``` ```# File 'Documentation/ams/geometry.rb', line 139 def is_point_on_edge?(point, edge) end```

### .is_point_on_face?(point, face) ⇒ Boolean

Determine whether a particular point is on face.

Parameters:

• point (Geom::Point3d)
• face (Sketchup::Face)

Returns:

• (Boolean)

Since:

• 3.3.0

 ``` 146 147``` ```# File 'Documentation/ams/geometry.rb', line 146 def is_point_on_face?(point, face) end```

### .is_point_on_triangle?(point, pt1, pt2, pt3) ⇒ Boolean

Determine whether a particular point is on triangle.

Parameters:

• point (Geom::Point3d)

The point to test.

• pt1 (Geom::Point3d)

The first vertex of the triangle.

• pt2 (Geom::Point3d)

The second vertex of the triangle.

• pt3 (Geom::Point3d)

The third vertex of the triangle.

Returns:

• (Boolean)

Since:

• 3.3.0

 ``` 155 156``` ```# File 'Documentation/ams/geometry.rb', line 155 def is_point_on_triangle?(point, pt1, pt2, pt3) end```

### .points_collinear?(points) ⇒ Boolean

Determine whether an array of points lie on the same line.

Parameters:

• points (Array<Geom::Point3d>)

Returns:

• (Boolean)

Since:

• 3.3.0

 ``` 91 92``` ```# File 'Documentation/ams/geometry.rb', line 91 def points_collinear?(points) end```

### .points_coplanar?(points) ⇒ Boolean

Determine whether an array of points lie on the same plane.

Parameters:

• points (Array<Geom::Point3d>)

Returns:

• (Boolean)

Since:

• 3.3.0

 ``` 111 112``` ```# File 'Documentation/ams/geometry.rb', line 111 def points_coplanar?(points) end```

### .product_vector(vector1, vector2) ⇒ Geom::Vector3d

Product two vectors - multiply their components.

Parameters:

• vector1 (Array<Numeric>, Geom::Vector3d)
• vector2 (Array<Numeric>, Geom::Vector3d)

Returns:

• (Geom::Vector3d)

Since:

• 3.6.0

 ``` 56 57``` ```# File 'Documentation/ams/geometry.rb', line 56 def product_vector(vector1, vector2) end```

### .raytest1(entities, point, vector, chg = false) ⇒ Array?

Cast a ray through the model that intersects with the given entities only.

Parameters:

• entities (Array<Sketchup::Drawingelement>)

An array of entities to include.

• point (Geom::Point3d, Array)

Ray position.

• vector (Geom::Vector3d, Array)

Ray direction.

• chg (Boolean) (defaults to: false)

Whether to consider hidden geometry.

Returns:

• (Array, nil)

A ray result.

Since:

• 3.5.0

 ``` 333 334``` ```# File 'Documentation/ams/geometry.rb', line 333 def raytest1(entities, point, vector, chg = false) end```

### .raytest2(entities, point, vector, chg = false) ⇒ Array?

Cast a ray through the model that intersects with all but the given entities.

Parameters:

• entities (Array<Sketchup::Drawingelement>)

An array of entities to ignore.

• point (Geom::Point3d, Array)

Ray position.

• vector (Geom::Vector3d, Array)

Ray direction.

• chg (Boolean) (defaults to: false)

Whether to consider hidden geometry.

Returns:

• (Array, nil)

A ray result.

Since:

• 3.5.0

 ``` 346 347``` ```# File 'Documentation/ams/geometry.rb', line 346 def raytest2(entities, point, vector, chg = false) end```

### .raytest3(point, vector, chg = false) ⇒ Array?

Note:

A face is considered transparent if front or back side, depending on which the ray hits, has a material with alpha less than 255.

Cast a ray that intersects with non-transparent faces only; a ray that passes through all the transparent faces and stops when hits a solid face.

Parameters:

• point (Geom::Point3d, Array)

Ray position.

• vector (Geom::Vector3d, Array)

Ray direction.

• chg (Boolean) (defaults to: false)

Whether to consider hidden geometry.

Returns:

• (Array, nil)

A ray result.

Since:

• 3.5.0

 ``` 359 360``` ```# File 'Documentation/ams/geometry.rb', line 359 def raytest3(point, vector, chg = false) end```

### .rotate_matrix_xaxis_to_dir(transformation, direction) ⇒ Geom::Transformation

Rotate a transformation matrix so that its X-axis aligns with a directing vector.

Parameters:

• transformation (Geom::Transformation)
• direction (Geom::Vector)

Returns:

• (Geom::Transformation)

Since:

• 3.5.0

 ``` 216 217``` ```# File 'Documentation/ams/geometry.rb', line 216 def rotate_matrix_xaxis_to_dir(transformation, direction) end```

### .rotate_matrix_yaxis_to_dir(transformation, direction) ⇒ Geom::Transformation

Rotate a transformation matrix so that its Y-axis aligns with a directing vector.

Parameters:

• transformation (Geom::Transformation)
• direction (Geom::Vector)

Returns:

• (Geom::Transformation)

Since:

• 3.5.0

 ``` 225 226``` ```# File 'Documentation/ams/geometry.rb', line 225 def rotate_matrix_yaxis_to_dir(transformation, direction) end```

### .rotate_matrix_zaxis_to_dir(transformation, direction) ⇒ Geom::Transformation

Rotate a transformation matrix so that its Z-axis aligns with a directing vector.

Parameters:

• transformation (Geom::Transformation)
• direction (Geom::Vector)

Returns:

• (Geom::Transformation)

Since:

• 3.5.0

 ``` 234 235``` ```# File 'Documentation/ams/geometry.rb', line 234 def rotate_matrix_zaxis_to_dir(transformation, direction) end```

### .rotate_vector(vector, normal, angle) ⇒ Geom::Vector3d

Rotate vector at a normal.

Parameters:

• vector (Geom::Vector3d)

The vector to rotate.

• normal (Geom::Vector3d)

The normal to rotate against.

• angle (Numeric)

The angle to rotate in radians.

Returns:

• (Geom::Vector3d)

The rotated vector.

Since:

• 3.5.0

 ``` 65 66``` ```# File 'Documentation/ams/geometry.rb', line 65 def rotate_vector(vector, normal, angle) end```

### .scale_matrix(matrix, scale) ⇒ Geom::Transformation

Scale matrix axes.

Parameters:

• matrix (Array<Numeric>, Geom::Transformation)
• scale (Array<Numeric>, Geom::Vector3d)

Returns:

• (Geom::Transformation)

Since:

• 3.6.0

 ``` 48 49``` ```# File 'Documentation/ams/geometry.rb', line 48 def scale_matrix(matrix, scale) end```

### .scale_point(point, scale) ⇒ Geom::Point3d

Scale point.

Parameters:

• point (Array<Numeric>, Geom::Point3d)
• scale (Numeric)

Returns:

• (Geom::Point3d)

Since:

• 3.5.0

 ``` 32 33``` ```# File 'Documentation/ams/geometry.rb', line 32 def scale_point(point, scale) end```

### .scale_vector(vector, scale) ⇒ Geom::Vector3d

Scale vector.

Parameters:

• vector (Array<Numeric>, Geom::Vector3d)
• scale (Numeric)

Returns:

• (Geom::Vector3d)

Since:

• 3.5.0

 ``` 40 41``` ```# File 'Documentation/ams/geometry.rb', line 40 def scale_vector(vector, scale) end```

### .set_matrix_scale(transformation, scale) ⇒ Geom::Transformation

Set the scale of axes of a transformation matrix.

Parameters:

• transformation (Geom::Transformation, Array<Numeric>)
• scale (Geom::Vector3d, Array<Numeric>)

An array of three numeric values, representing the scale ratios of the X-axis, Y-axis, and Z-axis.

Returns:

• (Geom::Transformation)

A new, scaled transformation matrix.

Since:

• 3.3.0

 ``` 181 182``` ```# File 'Documentation/ams/geometry.rb', line 181 def set_matrix_scale(transformation, scale) end```

### .sort_polygon_points(points) ⇒ Array<Geom::Point3d>

Note:

A polygon must be convex for the points to be sorted correctly.

Note:

If all points are collinear, then they won't be sorted and an array of unique points will be returned.

Sort an array of points in a counter clockwise direction.

Parameters:

• points (Array<Geom::Point3d>)

Returns:

• (Array<Geom::Point3d>)

An array of sorted points.

Since:

• 3.3.0

 ``` 120 121``` ```# File 'Documentation/ams/geometry.rb', line 120 def sort_polygon_points(points) end```

### .transition_camera(camera1, camera2, ratio) ⇒ Sketchup::Camera

Transition between two cameras.

Parameters:

• camera1 (Sketchup::Camera)
• camera2 (Sketchup::Camera)
• ratio (Numeric)

A value between 0.0 and 1.0.

Returns:

• (Sketchup::Camera)

Since:

• 3.3.0

 ``` 242 243``` ```# File 'Documentation/ams/geometry.rb', line 242 def transition_camera(camera1, camera2, ratio) end```

### .transition_color(color1, color2, ratio) ⇒ Sketchup::Color

Transition between two colors.

Parameters:

• color1 (Sketchup::Color)
• color2 (Sketchup::Color)
• ratio (Numeric)

A value between 0.0 and 1.0.

Returns:

• (Sketchup::Color)

Since:

• 3.3.0

 ``` 250 251``` ```# File 'Documentation/ams/geometry.rb', line 250 def transition_color(color1, color2, ratio) end```

### .transition_number(number1, number2, ratio) ⇒ Numeric

between 0.0 and 1.0.

Returns:

• (Numeric)

Since:

• 3.3.0

 ``` 291 292``` ```# File 'Documentation/ams/geometry.rb', line 291 def transition_number(number1, number2, ratio) end```

### .transition_point(point1, point2, ratio) ⇒ Geom::Point3d

Transition between two points.

Parameters:

• point1 (Geom::Point3d)
• point2 (Geom::Point3d)
• ratio (Numeric)

A value, not necessarily between 0.0 and 1.0.

Returns:

• (Geom::Point3d)

Since:

• 3.3.0

 ``` 259 260``` ```# File 'Documentation/ams/geometry.rb', line 259 def transition_point(point1, point2, ratio) end```

### .transition_transformation(transformation1, transformation2, ratio) ⇒ Geom::Transformation

Note:

For the function to work properly, both transformation matrices must be uniform and non-flipped. They can, however, since version 3.5.0, have scaled axes.

Transition between two transformation matrices.

Parameters:

• transformation1 (Geom::Transformation)
• transformation2 (Geom::Transformation)
• ratio (Numeric)

A value, not necessarily between 0.0 and 1.0.

Returns:

• (Geom::Transformation)

Since:

• 3.3.0

 ``` 282 283``` ```# File 'Documentation/ams/geometry.rb', line 282 def transition_transformation(transformation1, transformation2, ratio) end```

### .transition_vector(vector1, vector2, ratio) ⇒ Geom::Vector3d

Note:

Unlike the transition_point function, this function rotates and scales vector1 to vector2 a specific ratio.

Transition between two vectors.

Parameters:

• vector1 (Geom::Vector3d)
• vector2 (Geom::Vector3d)
• ratio (Numeric)

A value, not necessarily between 0.0 and 1.0.

Returns:

• (Geom::Vector3d)

Since:

• 3.3.0

 ``` 270 271``` ```# File 'Documentation/ams/geometry.rb', line 270 def transition_vector(vector1, vector2, ratio) end```