primitives

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Copyright 2025 César Nieto Sánchez

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Line

type Line struct {
	Point1 *Point // Starting point of the line
	Point2 *Point // Ending point of the line
}

Line represents a line in 2D space defined by two points (Point1 and Point2).

func NewLine

func NewLine(pa, pb *Point) *Line

NewLine creates a new Line instance.

Arguments:

pa (*Point): The first point defining the line.
pb (*Point): The second point defining the line.

Returns:

*Line: A pointer to the newly created Line object.

func (Line) Dimension

func (v Line) Dimension() int

Dimension returns the dimension of the line.

Returns:

int: The dimension of the line.

func (Line) Length

func (l Line) Length() float64

Length calculates the length of the line.

The length is computed as the norm of the direction vector.

Returns:

float64: The length of the line.

func (Line) String

func (l Line) String() string

String returns a string representation of the Line object.

Returns:

string: A string representation of the Line object.

func (Line) VectorDirector

func (l Line) VectorDirector() *Vector

VectorDirector calculates the direction vector of the line.

The direction vector is computed as the difference between Point2 and Point1.

Returns:

*Vector2D: A pointer to a Vector2D representing the direction of the line.

type Point

type Point struct {
	*mat.VecDense
}

Point represents a point in an n-dimensional space.

This struct wraps a `gonum` VecDense to provide additional functionality for representing and manipulating points in n-dimensional geometry.

func NewPoint

func NewPoint(coordinates []float64) *Point

NewPoint creates a new Point instance.

Arguments:

coordinates ([]float64): A slice of float64 values representing the coordinates of the point.

Returns:

*Point: A pointer to the newly created Point instance.

Example:

// Create a 3D point with coordinates (1.0, 2.0, 3.0):
point := NewPoint([]float64{1.0, 2.0, 3.0})

func (Point) Dimension

func (v Point) Dimension() int

Dimension returns the dimension of the point.

This method retrieves the length of the underlying vector, which corresponds to the number of dimensions of the point.

Returns:

int: The number of dimensions of the point.

Example:

point := NewPoint([]float64{1.0, 2.0, 3.0})
fmt.Println(point.Dimension()) // Output: 3

func (Point) String

func (p Point) String() string

String returns a string representation of the Point object.

Returns:

string: A string representation of the Point object in the format "Point{<formatted vector>}".

Example:

point := NewPoint([]float64{1.0, 2.0})
fmt.Println(point) // Output: Point{1.0  2.0}

type Vector

type Vector struct {
	*mat.VecDense
}

Vector represents a vector, which is a mathematical entity defined by its components.

func NewVector

func NewVector(coordinates []float64) *Vector

NewVector creates a new Vector instance.

Arguments:

  • coordinates ([]float64): A slice of float64 values representing the vector's components.

Returns:

  • *Vector: A pointer to the newly created Vector.

func NewVectorTwoPoints

func NewVectorTwoPoints(p1, p2 *Point) *Vector

NewVectorTwoPoints creates a vector from two points.

Arguments:

  • p1 (*Point): The starting point of the vector.
  • p2 (*Point): The ending point of the vector.

Returns:

  • *Vector: A pointer to the newly created Vector representing the difference between p2 and p1.

Panics:

  • If the dimensions of p1 and p2 are not equal.

func (Vector) Dimension

func (v Vector) Dimension() int

Dimension returns the dimension (number of components) of the vector.

Returns:

  • int: The dimension of the vector.

func (Vector) Length

func (v Vector) Length() float64

Length computes the Euclidean length (2-norm) of the vector.

Returns:

  • float64: The Euclidean length of the vector.

func (Vector) String

func (v Vector) String() string

String returns a string representation of the Vector object.

Returns:

  • string: A string representation of the Vector.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL