Class: Geom::Vector2d

Inherits:
Object
  • Object
show all
Defined in:
lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb

Overview

The Vector2d class represents vectors in a 2 dimensional space. Vectors in LayOut have a direction and a length, but not a starting point.

There are numerous tutorials on 2D vectors available on the internet.

Version:

  • LayOut 2018

Instance Method Summary collapse

Constructor Details

#initializeGeom::Vector2d #initialize(x, y) ⇒ Geom::Vector2d #initialize(vector) ⇒ Geom::Vector2d

The new method creates a new Geom::Vector2d.

Examples:

# A vector that runs along the X axis.
vector = Geom::Vector2d.new(1, 0)

Overloads:

Version:

  • LayOut 2018



214
215
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 214

def initialize(*args)
end

Instance Method Details

#%(vector) ⇒ Object

The #% method returns the dot product between two Geom::Vector2d. This is an alias of the dot method.

Examples:

vector = Geom::Vector2d.new(0, 2)
vector2 = Geom::Vector2d.new(1, 0)
d2 = vector % vector2

Parameters:

Returns:

  • The dot product of the vectors

Version:

  • LayOut 2018



27
28
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 27

def %(vector)
end

#*(vector) ⇒ Geom::Vector2d

The #* method returns the cross product between two Geom::Vector2d. This is an alias of the cross method.

Examples:

vector = Geom::Vector2d.new(1, 0)
vector2 = Geom::Vector2d.new(0, 1)
cross = vector * vector

Parameters:

Returns:

Version:

  • LayOut 2018



43
44
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 43

def *(vector)
end

#+(vector) ⇒ Geom::Vector2d

The #+ method adds a Geom::Vector2d to this one.

Examples:

vector = Geom::Vector2d.new(0, 2)
vector2 = Geom::Vector2d.new(1, 0)
new_vector = vector + vector2

Parameters:

Returns:

Version:

  • LayOut 2018



58
59
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 58

def +(vector)
end

#-(vector) ⇒ Geom::Vector2d

The #- method subtracts a Geom::Vector2d from this one.

Examples:

vector = Geom::Vector2d.new(0, 2)
vector2 = Geom::Vector2d.new(1, 0)
new_vector = vector - vector2

Parameters:

Returns:

Version:

  • LayOut 2018



73
74
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 73

def -(vector)
end

#==(vector) ⇒ Boolean

The #== method returns whether two Geom::Vector2d are equal within tolerance.

Examples:

vector = Geom::Vector2d.new(1, 0)
vector2 = Geom::Vector2d.new(0,1)
# Returns false
status = vector == vector2

Parameters:

Returns:

  • (Boolean)

Version:

  • LayOut 2018



90
91
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 90

def ==(vector)
end

#[](index) ⇒ Numeric

The #[] method returns the value of the Geom::Vector2d at the specified index.

Examples:

vector = Geom::Vector2d.new(1, 2)
# retrieves the y value of 2
yvalue = vector[1]

Parameters:

  • index (Integer)

    The index into an array of two coordinates.

Returns:

  • (Numeric)

    The value for the x or y coordinate.

Version:

  • LayOut 2018



107
108
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 107

def [](index)
end

#[]=(index, value) ⇒ Numeric

The #[]= method sets the x or y value of the Geom::Vector2d based on the specific index of the value.

Examples:

point = Geom::Vector2d.new(1,2)
point[1] = 4

Parameters:

Returns:

  • (Numeric)

    The new x or y value if successful

Version:

  • LayOut 2018



127
128
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 127

def []=(index, value)
end

#angle_between(vector) ⇒ Numeric

The #angle_between method computes the angle in radians between the Geom::Vector2d and another Geom::Vector2d.

Examples:

vector = Geom::Vector2d.new(1, 0)
vector2 = Geom::Vector2d.new(-1, 0)
# returns PI
angle = vector.angle_between(vector2)

Parameters:

Returns:

  • (Numeric)

    The angle (in radians)

Version:

  • LayOut 2018



144
145
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 144

def angle_between(vector)
end

#cloneGeom::Vector2d

The #clone method makes a copy of the Geom::Vector2d. This method is equivalent to vec2 = Geom::Vector2d.new(vec).

Examples:

vector = Geom::Vector2d.new(1, 0)
vector2 = vector.clone

Returns:

Version:

  • LayOut 2018



157
158
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 157

def clone
end

#cross(vector) ⇒ Geom::Vector2d

The #* method returns the cross product between two Geom::Vector2d. This is an alias of the cross method.

Examples:

vector = Geom::Vector2d.new(1, 0)
vector2 = Geom::Vector2d.new(0, 1)
cross = vector * vector

Parameters:

Returns:

Version:

  • LayOut 2018



173
174
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 173

def cross(vector)
end

#dot(vector) ⇒ Object

The #% method returns the dot product between two Geom::Vector2d. This is an alias of the dot method.

Examples:

vector = Geom::Vector2d.new(0, 2)
vector2 = Geom::Vector2d.new(1, 0)
d2 = vector % vector2

Parameters:

Returns:

  • The dot product of the vectors

Version:

  • LayOut 2018



189
190
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 189

def dot(vector)
end

#inspectString

The #inspect method formats the Geom::Vector2d as a string.

Examples:

point = Geom::Point2d.new(1, 2)
string = point.inspect

Returns:

Version:

  • LayOut 2018



226
227
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 226

def inspect
end

#lengthLength

The #length method returns the length of the Geom::Vector2d.

Examples:

vector = Geom::Vector2d.new(0, 4)
# returns 4
l = vector.length

Returns:

Version:

  • LayOut 2018



239
240
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 239

def length
end

#length=(length) ⇒ Numeric

The #length= method sets the length of the Geom::Vector2d. The new length must not be 0.

Examples:

vector = Geom::Vector2d.new(0, 4)
l = vector.length
vector.length = 2

Parameters:

Returns:

Version:

  • LayOut 2018



256
257
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 256

def length=(length)
end

#normalizeGeom::Vector2d

The #normalize method returns a Geom::Vector2d that is a unit vector of the Geom::Vector2d.

Examples:

vector = Geom::Vector2d.new(0, 4)
# returns a new Vector2d(0, 1)
vector2 = vector.normalize

Returns:

Version:

  • LayOut 2018



270
271
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 270

def normalize
end

#normalize!Object

The #normalize! method converts a Geom::Vector2d vector into a unit vector. Another way to do this is vector.length = 1

Examples:

vector = Geom::Vector2d.new(0, 4)
# modifies vector to be the Vector2d(0, 1)
vector.normalize!

Version:

  • LayOut 2018



282
283
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 282

def normalize!
end

#parallel?(vector) ⇒ Boolean

The #parallel? method determines if the Geom::Vector2d is parallel to another Geom::Vector2d to within tolerance.

Examples:

vector = Geom::Vector2d.new(0, 1)
vector2 = Geom::Vector2d.new(1, 2)
# returns true
status = vector.parallel?(vector2)

Parameters:

Returns:

  • (Boolean)

Version:

  • LayOut 2018



299
300
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 299

def parallel?(vector)
end

#perpendicular?(vector) ⇒ Boolean

The #perpendicular? method determines if the Geom::Vector2d is perpendicular to another Geom::Vector2d to within tolerance.

Examples:

vector = Geom::Vector2d.new(0, 1)
vector2 = Geom::Vector2d.new(1, 2)
# returns false
status = vector.perpendicular?(vector2)

Parameters:

Returns:

  • (Boolean)

Version:

  • LayOut 2018



316
317
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 316

def perpendicular?(vector)
end

#reverseGeom::Vector2d

The #reverse method returns a new Geom::Vector2d that is the reverse of the Geom::Vector2d, leaving the original unchanged.

Examples:

vector = Geom::Vector2d.new(1, 2)
# returns the Vector2d(-1, -2)
vector2 = vector.reverse

Returns:

Version:

  • LayOut 2018



330
331
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 330

def reverse
end

#reverse!Object

The #reverse! method reverses the Geom::Vector2d in place.

Examples:

vector = Geom::Vector2d.new(1, 2)
# modifies vector to be the Vector2d(-1, -2)
vector.reverse!

Version:

  • LayOut 2018



341
342
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 341

def reverse!
end

#same_direction?(vector) ⇒ Boolean

The #same_direction? method determines if the Geom::Vector2d is parallel to and in the same direction as another Geom::Vector2d within tolerance.

Examples:

vector = Geom::Vector2d.new(0, 1)
vector2 = Geom::Vector2d.new(1, 2)
# returns true
status = vector.sime_direction?(vector2)

Parameters:

Returns:

  • (Boolean)

Version:

  • LayOut 2018



358
359
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 358

def same_direction?(vector)
end

#set!(vector) ⇒ Geom::Vector2d #set!(x, y) ⇒ Geom::Vector2d

The #set! method sets the values of the Geom::Vector2d.

Examples:

vector = Geom::Vector2d.new(1, 2)
vector = vector.set!([4, 5])

Overloads:

Version:

  • LayOut 2018



379
380
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 379

def set!(*args)
end

#to_aArray(Numeric, Numeric)

The #to_a method retrieves the coordinates of the Geom::Vector2d in an Array.

Examples:

a = vector.to_a

Returns:

Version:

  • LayOut 2018



391
392
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 391

def to_a
end

#to_sString

The #to_s method returns a string representation of the Geom::Vector2d.

Examples:

point = Geom::Vector2d.new(1, 2)
str = point.to_s

Returns:

Version:

  • LayOut 2018



403
404
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 403

def to_s
end

#transform(transform) ⇒ Geom::Vector2d

The #transform method applies a transformation to a vector, returning a new vector. The original vector is unchanged by this method.

Examples:

vector = Geom::Vector2d.new(4, 5)
transformation = Geom::Transformation2d.new([1, 0, 0, 1, 2, 3])
# vector2 will be (6, 8)
vector2 = vector.transform(transformation)

Parameters:

Returns:

Version:

  • LayOut 2019



421
422
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 421

def transform(transform)
end

#transform!(transform) ⇒ Geom::Vector2d

The #transform! method applies a transformation to a vector. The vector itself is modified.

Examples:

vector = Geom::Vector2d.new(4, 5)
transformation = Geom::Transformation2d.new([1, 0, 0, 1, 2, 3])
# vector will be (6, 8)
vector.transform!(transformation)

Parameters:

Returns:

Version:

  • LayOut 2019



439
440
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 439

def transform!(transform)
end

#unit_vector?Boolean

The #unit_vector? method returns whether the Geom::Vector2d is a unit vector. This is equivalent to vector.length == 1.0

Examples:

vector = Geom::Vector2d.new(1, 0)
# returns true
status = vector.unit_vector

Returns:

  • (Boolean)

Version:

  • LayOut 2018



453
454
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 453

def unit_vector?
end

#valid?Boolean

The #valid? method verifies if a Geom::Vector2d is valid. A Geom::Vector2d is valid if its length is not zero.

Examples:

vector = Geom::Vector2d.new(0, 4)
status = vector.valid

Returns:

  • (Boolean)

Version:

  • LayOut 2018



466
467
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 466

def valid?
end

#xNumeric

The #x method retrieves the x value of the Geom::Vector2d.

Examples:

vector = Geom::Vector2d.new(1, 2)
x = vector.x

Returns:

Version:

  • LayOut 2018



478
479
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 478

def x
end

#x=(x) ⇒ Numeric

The #x= method sets the x coordinate of the Geom::Vector2d.

Examples:

vector = Geom::Vector2d.new(1, 2)
vector.x = 7

Parameters:

Returns:

Version:

  • LayOut 2018



493
494
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 493

def x=(x)
end

#yNumeric

The #y method retrieves the y value of the Geom::Vector2d.

Examples:

vector = Geom::Vector2d.new(1, 2)
y = vector.y

Returns:

Version:

  • LayOut 2018



505
506
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 505

def y
end

#y=(y) ⇒ Numeric

The #y= method sets the y coordinate of the Geom::Vector2d.

Examples:

vector = Geom::Vector2d.new(1, 2)
vector.y = 7

Parameters:

Returns:

Version:

  • LayOut 2018



520
521
# File 'lib/sketchup-api-stubs/stubs/Geom/Vector2d.rb', line 520

def y=(y)
end