RobotCore
1.0
WPILib port to raspberry Pi
Toggle main menu visibility
Loading...
Searching...
No Matches
Vector.java
1
// Copyright (c) FIRST and other WPILib contributors.
2
// Open Source Software; you can modify and/or share it under the terms of
3
// the WPILib BSD license file in the root directory of this project.
4
5
package
org.wpilib.math.linalg;
6
7
import
java.util.Objects;
8
import
org.ejml.simple.SimpleMatrix;
9
import
org.wpilib.math.linalg.proto.VectorProto;
10
import
org.wpilib.math.linalg.struct.VectorStruct;
11
import
org.wpilib.math.numbers.N1;
12
import
org.wpilib.math.numbers.N3;
13
import
org.wpilib.math.util.Nat;
14
import
org.wpilib.math.util.Num;
15
import
org.wpilib.util.protobuf.Protobuf;
16
import
org.wpilib.util.protobuf.ProtobufSerializable;
17
import
org.wpilib.util.struct.Struct;
18
import
org.wpilib.util.struct.StructSerializable;
19
27
public
class
Vector
<R
extends
Num
> extends
Matrix
<R, N1>
28
implements
ProtobufSerializable
,
StructSerializable
{
34
public
Vector
(
Nat<R>
rows) {
35
super(rows,
Nat
.
N1
());
36
}
37
48
public
Vector
(SimpleMatrix storage) {
49
super(storage);
50
}
51
57
public
Vector
(
Matrix<R, N1>
other) {
58
super(other);
59
}
60
67
public
double
get
(
int
row) {
68
return
get
(row, 0);
69
}
70
71
@Override
72
public
Vector<R>
times(
double
value) {
73
return
new
Vector<>
(this.
m_storage
.scale(value));
74
}
75
76
@Override
77
public
Vector<R>
div(
int
value) {
78
return
new
Vector<>
(this.
m_storage
.divide(value));
79
}
80
81
@Override
82
public
Vector<R>
div(
double
value) {
83
return
new
Vector<>
(this.
m_storage
.divide(value));
84
}
85
92
public
final
Vector<R>
plus
(
Vector<R>
value) {
93
return
new
Vector<>
(this.
m_storage
.plus(Objects.requireNonNull(value).m_storage));
94
}
95
102
public
final
Vector<R>
minus
(
Vector<R>
value) {
103
return
new
Vector<>
(this.
m_storage
.minus(Objects.requireNonNull(value).m_storage));
104
}
105
112
public
double
dot
(
Vector<R>
other) {
113
double
dot
= 0.0;
114
115
for
(
int
i = 0; i <
getNumRows
(); ++i) {
116
dot
+=
get
(i, 0) * other.
get
(i, 0);
117
}
118
119
return
dot
;
120
}
121
127
public
double
norm
() {
128
return
Math.sqrt(
dot
(
this
));
129
}
130
136
public
Vector<R>
unit
() {
137
return
div(
norm
());
138
}
139
146
public
Vector<R>
projection
(
Vector<R>
other) {
147
return
other.times(
dot
(other)).div(other.
dot
(other));
148
}
149
157
public
static
Vector<N3>
cross
(
Vector<N3>
a,
Vector<N3>
b) {
158
return
VecBuilder
.
fill
(
159
a.
get
(1) * b.
get
(2) - a.
get
(2) * b.
get
(1),
160
a.
get
(2) * b.
get
(0) - a.
get
(0) * b.
get
(2),
161
a.
get
(0) * b.
get
(1) - a.
get
(1) * b.
get
(0));
162
}
163
171
public
static
final <R extends Num>
VectorProto<R>
getProto
(
Nat<R>
rows) {
172
return
new
VectorProto<>
(rows);
173
}
174
182
public
static
final <R extends Num>
VectorStruct<R>
getStruct
(
Nat<R>
rows) {
183
return
new
VectorStruct<>
(rows);
184
}
185
}
org.wpilib.math.linalg.Matrix< R, N1 >::getNumRows
final int getNumRows()
Definition
Matrix.java:114
org.wpilib.math.linalg.Matrix< R, N1 >::m_storage
final SimpleMatrix m_storage
Definition
Matrix.java:38
org.wpilib.math.linalg.Matrix< R, N1 >::Matrix
Matrix(Nat< R > rows, Nat< C > columns)
Definition
Matrix.java:46
org.wpilib.math.linalg.VecBuilder
Definition
VecBuilder.java:23
org.wpilib.math.linalg.VecBuilder.fill
static Vector< N1 > fill(double n1)
Definition
VecBuilder.java:46
org.wpilib.math.linalg.Vector
Definition
Vector.java:28
org.wpilib.math.linalg.Vector.unit
Vector< R > unit()
Definition
Vector.java:136
org.wpilib.math.linalg.Vector.get
double get(int row)
Definition
Vector.java:67
org.wpilib.math.linalg.Vector.Vector
Vector(Nat< R > rows)
Definition
Vector.java:34
org.wpilib.math.linalg.Vector.plus
final Vector< R > plus(Vector< R > value)
Definition
Vector.java:92
org.wpilib.math.linalg.Vector.norm
double norm()
Definition
Vector.java:127
org.wpilib.math.linalg.Vector.dot
double dot(Vector< R > other)
Definition
Vector.java:112
org.wpilib.math.linalg.Vector.getProto
static final< R extends Num > VectorProto< R > getProto(Nat< R > rows)
Definition
Vector.java:171
org.wpilib.math.linalg.Vector.cross
static Vector< N3 > cross(Vector< N3 > a, Vector< N3 > b)
Definition
Vector.java:157
org.wpilib.math.linalg.Vector.minus
final Vector< R > minus(Vector< R > value)
Definition
Vector.java:102
org.wpilib.math.linalg.Vector.Vector
Vector(SimpleMatrix storage)
Definition
Vector.java:48
org.wpilib.math.linalg.Vector.projection
Vector< R > projection(Vector< R > other)
Definition
Vector.java:146
org.wpilib.math.linalg.Vector.getStruct
static final< R extends Num > VectorStruct< R > getStruct(Nat< R > rows)
Definition
Vector.java:182
org.wpilib.math.linalg.Vector.Vector
Vector(Matrix< R, N1 > other)
Definition
Vector.java:57
org.wpilib.math.linalg.proto.VectorProto
Definition
VectorProto.java:15
org.wpilib.math.linalg.proto.VectorProto.VectorProto
VectorProto(Nat< R > rows)
Definition
VectorProto.java:23
org.wpilib.math.linalg.struct.VectorStruct
Definition
VectorStruct.java:14
org.wpilib.math.linalg.struct.VectorStruct.VectorStruct
VectorStruct(Nat< R > rows)
Definition
VectorStruct.java:22
org.wpilib.math.util.Num
Definition
Num.java:8
org.wpilib.math.util.Nat
Definition
Nat.java:41
org.wpilib.math.util.Nat.N1
static Nat< N1 > N1()
Definition
Nat.java:63
org.wpilib.util.protobuf.ProtobufSerializable
Definition
ProtobufSerializable.java:16
org.wpilib.util.struct.StructSerializable
Definition
StructSerializable.java:16
org
wpilib
math
linalg
Vector.java
Generated by
1.18.0