Class: Autocad::Line

Inherits:
Element show all
Defined in:
lib/autocad/line.rb

Overview

Represents a line entity in AutoCAD, providing access to geometric properties and spatial relationships.

Key Features:

  • Length calculation

  • Start/end point coordinates

  • 3D orientation properties

  • Thickness control

  • Geometric vector analysis

Geometric Relationships:

Normal (Z-axis)
   
   

Start ●───┼───● End


└─── Delta Vector

Examples:

Create and query a line

line = drawing.model.add_line([0,0,0], [5,5,0])
puts line.length  # => 7.0710678118654755
puts line.delta   # => (5.0, 5.0, 0.0)

Instance Attribute Summary

Attributes inherited from Element

#acad_type, #app, #ole_obj, #original

Instance Method Summary collapse

Methods inherited from Element

#[], #app_ole_obj, #clone, convert_item, #delete, #do_update, #each_complex, #get_property_handler, #in_cell?, #initialize, #method_missing, #move, #move_ole, #move_x, #move_y, #ole_cell, ole_object?, #property_handler, #read_ole, #redraw, #update, #updated?, #write_ole

Methods included from ElementTrait

#autocad_type, #block_reference?, #bounds, #cell?, #def, #drawing, #explode, #graphical?, #has_tags?, #highlight, #id_from_record, #inspect, #model, #parent, #pviewport?, #select, #text?, #to_ole, #visible?

Constructor Details

This class inherits a constructor from Autocad::Element

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Autocad::Element

Instance Method Details

#deltaPoint3d

Directional vector from start to end point (equivalent to ‘end_point - start_point`).

Mathematical Properties:

  • X/Y/Z components = coordinate differences

  • Magnitude = line length

Examples:

line.delta  # => (5.0, 5.0, 0.0)
line.delta.magnitude == line.length  # => true

Returns:

  • (Point3d)

    The vector from start to end point



118
119
120
# File 'lib/autocad/line.rb', line 118

def delta
  Point3d.new ole_obj.Delta
end

#end_pointPoint3d

3D coordinates of the line’s endpoint in World Coordinate System (WCS).

Examples:

ending = line.end_point
puts ending  # => (5.0, 5.0, 0.0)

Returns:

  • (Point3d)

    The end point coordinates



71
72
73
# File 'lib/autocad/line.rb', line 71

def end_point
  Point3d.new(ole_obj.EndPoint)
end

#lengthFloat

Calculates the linear length of the line segment.

Examples:

line = drawing.model.add_line([0,0,0], [5,5,0])
puts line.length  # => 7.0710678118654755

Returns:

  • (Float)

    The length of the line



36
37
38
# File 'lib/autocad/line.rb', line 36

def length
  ole_obj.length
end

#line?Boolean

Type-check method confirming this is a line entity.

Examples:

line.line?  # => true

Returns:

  • (Boolean)

    Always returns true for Line objects



47
48
49
# File 'lib/autocad/line.rb', line 47

def line?
  true
end

#normalPoint3d

Unit vector perpendicular to the line’s plane (Z-axis direction by default).

Properties:

  • Always returns unit vector (magnitude = 1)

  • Affects shading and 3D operations

Examples:

line.normal  # => (0.0, 0.0, 1.0)

Returns:



86
87
88
# File 'lib/autocad/line.rb', line 86

def normal
  Point3d.new ole_obj.Normal
end

#start_pointPoint3d

3D coordinates of the line’s starting point in World Coordinate System (WCS).

Examples:

start = line.start_point
puts start  # => (0.0, 0.0, 0.0)

Returns:

  • (Point3d)

    The start point coordinates



59
60
61
# File 'lib/autocad/line.rb', line 59

def start_point
  Point3d.new(ole_obj.StartPoint)
end

#thicknessFloat

Extrusion thickness along the normal vector (3D effect).

Note:

  • Positive values extrude in normal direction

  • Negative values extrude opposite direction

  • 0 = 2D line

Examples:

line.thickness = 2.5  # Creates 3D prism

Returns:

  • (Float)

    The current thickness value



102
103
104
# File 'lib/autocad/line.rb', line 102

def thickness
  ole_obj.Thickness
end