Skip to content

Commit

Permalink
README
Browse files Browse the repository at this point in the history
  • Loading branch information
vaibhav11s committed Jun 16, 2022
1 parent 6e1e187 commit 457c240
Show file tree
Hide file tree
Showing 2 changed files with 269 additions and 266 deletions.
269 changes: 269 additions & 0 deletions vector2d/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
<!-- Code generated by gomarkdoc. DO NOT EDIT -->

# vector2d

```go
import "github.com/vaibhav11s/gopkgs/vector2d"
```

Package vector provides a simple 2D vector type on cartesian plane

## Index

- [func AngleBetween(v1, v2 *Vector2D) float32](<#func-anglebetween>)
- [func Cross(v1, v2 *Vector2D) float32](<#func-cross>)
- [func Dot(v1, v2 *Vector2D) float32](<#func-dot>)
- [type Vector2D](<#type-vector2d>)
- [func Add(v1, v2 *Vector2D) *Vector2D](<#func-add>)
- [func Copy(v *Vector2D) *Vector2D](<#func-copy>)
- [func FromAngle(angle float32, length ...float32) *Vector2D](<#func-fromangle>)
- [func New(x, y float32) *Vector2D](<#func-new>)
- [func Random(length ...float32) *Vector2D](<#func-random>)
- [func Sub(v1, v2 *Vector2D) *Vector2D](<#func-sub>)
- [func Unit(v *Vector2D) *Vector2D](<#func-unit>)
- [func (v *Vector2D) Add(v2 *Vector2D) *Vector2D](<#func-vector2d-add>)
- [func (v *Vector2D) AngleBetween(v2 *Vector2D) float32](<#func-vector2d-anglebetween>)
- [func (v *Vector2D) Copy() *Vector2D](<#func-vector2d-copy>)
- [func (v *Vector2D) Cross(v2 *Vector2D) float32](<#func-vector2d-cross>)
- [func (v *Vector2D) Dist(v2 *Vector2D) float32](<#func-vector2d-dist>)
- [func (v *Vector2D) Dot(v2 *Vector2D) float32](<#func-vector2d-dot>)
- [func (v *Vector2D) Equal(v2 *Vector2D, tolerance ...float32) bool](<#func-vector2d-equal>)
- [func (v *Vector2D) Heading() float32](<#func-vector2d-heading>)
- [func (v *Vector2D) Mag() float32](<#func-vector2d-mag>)
- [func (v *Vector2D) MagSq() float32](<#func-vector2d-magsq>)
- [func (v *Vector2D) Mult(scalar float32) *Vector2D](<#func-vector2d-mult>)
- [func (v *Vector2D) Normalize() *Vector2D](<#func-vector2d-normalize>)
- [func (v *Vector2D) Resize(mag float32) *Vector2D](<#func-vector2d-resize>)
- [func (v *Vector2D) Rotate(angle float32) *Vector2D](<#func-vector2d-rotate>)
- [func (v *Vector2D) SetHeading(angle float32) *Vector2D](<#func-vector2d-setheading>)
- [func (v *Vector2D) String() string](<#func-vector2d-string>)
- [func (v *Vector2D) Sub(v2 *Vector2D) *Vector2D](<#func-vector2d-sub>)


## func AngleBetween

```go
func AngleBetween(v1, v2 *Vector2D) float32
```

Calculates and returns the angle between two vectors\. Returns NaN if any vector is a zero vector

## func Cross

```go
func Cross(v1, v2 *Vector2D) float32
```

Calculates the cross product of two vectors \~ give the value of the z axis component \(in 2D space\, the cross product is a vector perpendicular to the two input vectors\)

## func Dot

```go
func Dot(v1, v2 *Vector2D) float32
```

Calculates the dot product of two vectors

## type Vector2D

```go
type Vector2D struct {
X, Y float32
}
```

### func Add

```go
func Add(v1, v2 *Vector2D) *Vector2D
```

returns the sum of two vectors

### func Copy

```go
func Copy(v *Vector2D) *Vector2D
```

Gets a copy of the vector

### func FromAngle

```go
func FromAngle(angle float32, length ...float32) *Vector2D
```

Make a new 2D vector from an angle

### func New

```go
func New(x, y float32) *Vector2D
```

Creates a new 2D vector\. Two dimensional Euclidean vector\.

### func Random

```go
func Random(length ...float32) *Vector2D
```

Make a new 2D vector from a random angle of length 1 \(default\) or a given length

### func Sub

```go
func Sub(v1, v2 *Vector2D) *Vector2D
```

returns the difference of two vectors

### func Unit

```go
func Unit(v *Vector2D) *Vector2D
```

Gives a unit vector in dirction of the vector

### func \(\*Vector2D\) Add

```go
func (v *Vector2D) Add(v2 *Vector2D) *Vector2D
```

add a vector to the current vector\. Modify \+ Returns self

### func \(\*Vector2D\) AngleBetween

```go
func (v *Vector2D) AngleBetween(v2 *Vector2D) float32
```

Calculates and returns the angle with another vector Returns NaN if any vector is a zero vector

### func \(\*Vector2D\) Copy

```go
func (v *Vector2D) Copy() *Vector2D
```

Gets a copy of the vector

### func \(\*Vector2D\) Cross

```go
func (v *Vector2D) Cross(v2 *Vector2D) float32
```

Calculates the cross product with another vector \~ give the value of the z axis component \(in 2D space\, the cross product is a vector perpendicular to the two input vectors\)

### func \(\*Vector2D\) Dist

```go
func (v *Vector2D) Dist(v2 *Vector2D) float32
```

Calculates the Euclidean distance between two points \(considering a point as a vector object\)

### func \(\*Vector2D\) Dot

```go
func (v *Vector2D) Dot(v2 *Vector2D) float32
```

Calculates the dot product with another vector

### func \(\*Vector2D\) Equal

```go
func (v *Vector2D) Equal(v2 *Vector2D, tolerance ...float32) bool
```

Checks whether two vectors are equal\. optional tolerence value can be passed as a parameter to check for equality within a tolerance\, abs\(v\.x \- v2\.x\) \< tolerance and abs\(v\.y \- v2\.y\) \< tolerance

### func \(\*Vector2D\) Heading

```go
func (v *Vector2D) Heading() float32
```

Calculate the angle of rotation for the vector

### func \(\*Vector2D\) Mag

```go
func (v *Vector2D) Mag() float32
```

Calculates the magnitude \(length\) of the vector and returns the result as a float this is simply the equation sqrt\(x\*x \+ y\*y\)

### func \(\*Vector2D\) MagSq

```go
func (v *Vector2D) MagSq() float32
```

Calculates the squared magnitude of the vector and returns the result as a float this is simply the equation \(x\*x \+ y\*y \+ z\*z\)

### func \(\*Vector2D\) Mult

```go
func (v *Vector2D) Mult(scalar float32) *Vector2D
```

Multiplies the vector by a scalar\. Modify \+ Returns self

### func \(\*Vector2D\) Normalize

```go
func (v *Vector2D) Normalize() *Vector2D
```

Normalize the vector to length 1 \(make it a unit vector\)\. Modify \+ Returns self

### func \(\*Vector2D\) Resize

```go
func (v *Vector2D) Resize(mag float32) *Vector2D
```

Set the magnitude of this vector to the value used for the len parameter\. Modify \+ Returns self

### func \(\*Vector2D\) Rotate

```go
func (v *Vector2D) Rotate(angle float32) *Vector2D
```

rotate the vector in the direction of the angle\. Modify \+ Returns self

### func \(\*Vector2D\) SetHeading

```go
func (v *Vector2D) SetHeading(angle float32) *Vector2D
```

Rotate the vector to a specific angle\, magnitude remains the same\. Modify \+ Returns self

### func \(\*Vector2D\) String

```go
func (v *Vector2D) String() string
```

Returns a string representation of the vector

### func \(\*Vector2D\) Sub

```go
func (v *Vector2D) Sub(v2 *Vector2D) *Vector2D
```

subtract a vector from the current vector\. Modify \+ Returns self



Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
Loading

0 comments on commit 457c240

Please sign in to comment.