RobotCore
1.0
WPILib port to raspberry Pi
Toggle main menu visibility
Loading...
Searching...
No Matches
Translation3d.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.geometry;
6
7
import
static
org.wpilib.units.Units.Meters;
8
9
import
io.avaje.jsonb.Json;
10
import
java.util.Collection;
11
import
java.util.Collections;
12
import
java.util.Comparator;
13
import
java.util.Objects;
14
import
org.wpilib.math.geometry.proto.Translation3dProto;
15
import
org.wpilib.math.geometry.struct.Translation3dStruct;
16
import
org.wpilib.math.interpolation.Interpolatable;
17
import
org.wpilib.math.linalg.VecBuilder;
18
import
org.wpilib.math.linalg.Vector;
19
import
org.wpilib.math.numbers.N3;
20
import
org.wpilib.math.util.MathUtil;
21
import
org.wpilib.units.measure.Distance;
22
import
org.wpilib.util.protobuf.ProtobufSerializable;
23
import
org.wpilib.util.struct.StructSerializable;
24
32
@Json
33
public
final
class
Translation3d
34
implements
Interpolatable
<Translation3d>,
ProtobufSerializable
,
StructSerializable
{
40
public
static
final
Translation3d
ZERO
=
new
Translation3d
();
41
42
@Json.Property(
"x"
)
43
private
final
double
m_x;
44
45
@Json.Property(
"y"
)
46
private
final
double
m_y;
47
48
@Json.Property(
"z"
)
49
private
final
double
m_z;
50
52
public
Translation3d
() {
53
this
(0.0, 0.0, 0.0);
54
}
55
63
@Json.Creator
64
public
Translation3d
(
double
x,
double
y,
double
z) {
65
m_x = x;
66
m_y = y;
67
m_z = z;
68
}
69
77
public
Translation3d
(
double
distance,
Rotation3d
angle) {
78
final
var rectangular =
new
Translation3d
(distance, 0.0, 0.0).rotateBy(angle);
79
m_x = rectangular.getX();
80
m_y = rectangular.getY();
81
m_z = rectangular.getZ();
82
}
83
92
public
Translation3d
(Distance x, Distance y, Distance z) {
93
this
(x.in(Meters), y.in(Meters), z.in(Meters));
94
}
95
103
public
Translation3d
(
Translation2d
translation) {
104
this
(translation.
getX
(), translation.
getY
(), 0.0);
105
}
106
113
public
Translation3d
(
Vector<N3>
vector) {
114
this
(vector.
get
(0), vector.
get
(1), vector.
get
(2));
115
}
116
125
public
double
getDistance
(
Translation3d
other) {
126
double
dx = other.m_x - m_x;
127
double
dy = other.m_y - m_y;
128
double
dz = other.m_z - m_z;
129
return
Math.sqrt(dx * dx + dy * dy + dz * dz);
130
}
131
141
public
double
getSquaredDistance
(
Translation3d
other) {
142
double
dx = other.m_x - m_x;
143
double
dy = other.m_y - m_y;
144
double
dz = other.m_z - m_z;
145
return
dx * dx + dy * dy + dz * dz;
146
}
147
153
public
double
getX
() {
154
return
m_x;
155
}
156
162
public
double
getY
() {
163
return
m_y;
164
}
165
171
public
double
getZ
() {
172
return
m_z;
173
}
174
180
public
Distance
getMeasureX
() {
181
return
Meters.of(m_x);
182
}
183
189
public
Distance
getMeasureY
() {
190
return
Meters.of(m_y);
191
}
192
198
public
Distance
getMeasureZ
() {
199
return
Meters.of(m_z);
200
}
201
207
public
Vector<N3>
toVector
() {
208
return
VecBuilder
.
fill
(m_x, m_y, m_z);
209
}
210
216
public
double
getNorm
() {
217
return
Math.sqrt(m_x * m_x + m_y * m_y + m_z * m_z);
218
}
219
226
public
double
getSquaredNorm
() {
227
return
m_x * m_x + m_y * m_y + m_z * m_z;
228
}
229
239
public
Translation3d
rotateBy
(
Rotation3d
other) {
240
final
var p =
new
Quaternion
(0.0, m_x, m_y, m_z);
241
final
var qprime = other.
getQuaternion
().
times
(p).
times
(other.
getQuaternion
().
inverse
());
242
return
new
Translation3d
(qprime.getX(), qprime.getY(), qprime.getZ());
243
}
244
252
public
Translation3d
rotateAround
(
Translation3d
other,
Rotation3d
rot) {
253
return
this.
minus
(other).
rotateBy
(rot).
plus
(other);
254
}
255
264
public
double
dot
(
Translation3d
other) {
265
return
m_x * other.m_x + m_y * other.m_y + m_z * other.m_z;
266
}
267
278
public
Vector<N3>
cross
(
Translation3d
other) {
279
return
VecBuilder
.
fill
(
280
m_y * other.m_z - other.m_y * m_z,
281
m_z * other.m_x - other.m_z * m_x,
282
m_x * other.m_y - other.m_x * m_y);
283
}
284
290
public
Translation2d
toTranslation2d
() {
291
return
new
Translation2d
(m_x, m_y);
292
}
293
303
public
Translation3d
plus
(
Translation3d
other) {
304
return
new
Translation3d
(m_x + other.m_x, m_y + other.m_y, m_z + other.m_z);
305
}
306
316
public
Translation3d
minus
(
Translation3d
other) {
317
return
new
Translation3d
(m_x - other.m_x, m_y - other.m_y, m_z - other.m_z);
318
}
319
326
public
Translation3d
unaryMinus
() {
327
return
new
Translation3d
(-m_x, -m_y, -m_z);
328
}
329
338
public
Translation3d
times
(
double
scalar) {
339
return
new
Translation3d
(m_x * scalar, m_y * scalar, m_z * scalar);
340
}
341
350
public
Translation3d
div
(
double
scalar) {
351
return
new
Translation3d
(m_x / scalar, m_y / scalar, m_z / scalar);
352
}
353
360
public
Translation3d
nearest
(Collection<Translation3d> translations) {
361
return
Collections.min(translations, Comparator.comparing(this::getDistance));
362
}
363
364
@Override
365
public
String toString() {
366
return
String.format(
"Translation3d(X: %.2f, Y: %.2f, Z: %.2f)"
, m_x, m_y, m_z);
367
}
368
375
@Override
376
public
boolean
equals
(Object obj) {
377
return
obj instanceof
Translation3d
other
378
&& Math.abs(other.m_x - m_x) < 1E-9
379
&& Math.abs(other.m_y - m_y) < 1E-9
380
&& Math.abs(other.m_z - m_z) < 1E-9;
381
}
382
383
@Override
384
public
int
hashCode() {
385
return
Objects.hash(m_x, m_y, m_z);
386
}
387
388
@Override
389
public
Translation3d
interpolate(
Translation3d
endValue,
double
t) {
390
return
new
Translation3d
(
391
MathUtil.lerp(
this
.getX(), endValue.getX(), t),
392
MathUtil.lerp(
this
.getY(), endValue.getY(), t),
393
MathUtil.lerp(
this
.getZ(), endValue.getZ(), t));
394
}
395
397
public
static
final
Translation3dProto
proto
=
new
Translation3dProto
();
398
400
public
static
final
Translation3dStruct
struct
= new
Translation3dStruct
();
401
}
org.wpilib.math.geometry.Quaternion.Quaternion
Quaternion()
Definition
Quaternion.java:29
org.wpilib.math.geometry.Quaternion.times
Quaternion times(double scalar)
Definition
Quaternion.java:94
org.wpilib.math.geometry.Quaternion.inverse
Quaternion inverse()
Definition
Quaternion.java:176
org.wpilib.math.geometry.Rotation3d
Definition
Rotation3d.java:71
org.wpilib.math.geometry.Rotation3d.getQuaternion
Quaternion getQuaternion()
Definition
Rotation3d.java:476
org.wpilib.math.geometry.Translation2d
Definition
Translation2d.java:34
org.wpilib.math.geometry.Translation2d.getY
double getY()
Definition
Translation2d.java:140
org.wpilib.math.geometry.Translation2d.Translation2d
Translation2d()
Definition
Translation2d.java:49
org.wpilib.math.geometry.Translation2d.getX
double getX()
Definition
Translation2d.java:131
org.wpilib.math.geometry.Translation3d.Translation3d
Translation3d(double distance, Rotation3d angle)
Definition
Translation3d.java:77
org.wpilib.math.geometry.Translation3d.Translation3d
Translation3d(double x, double y, double z)
Definition
Translation3d.java:64
org.wpilib.math.geometry.Translation3d.getMeasureY
Distance getMeasureY()
Definition
Translation3d.java:189
org.wpilib.math.geometry.Translation3d.cross
Vector< N3 > cross(Translation3d other)
Definition
Translation3d.java:278
org.wpilib.math.geometry.Translation3d.getMeasureX
Distance getMeasureX()
Definition
Translation3d.java:180
org.wpilib.math.geometry.Translation3d.rotateBy
Translation3d rotateBy(Rotation3d other)
Definition
Translation3d.java:239
org.wpilib.math.geometry.Translation3d.rotateAround
Translation3d rotateAround(Translation3d other, Rotation3d rot)
Definition
Translation3d.java:252
org.wpilib.math.geometry.Translation3d.plus
Translation3d plus(Translation3d other)
Definition
Translation3d.java:303
org.wpilib.math.geometry.Translation3d.getSquaredDistance
double getSquaredDistance(Translation3d other)
Definition
Translation3d.java:141
org.wpilib.math.geometry.Translation3d.Translation3d
Translation3d()
Definition
Translation3d.java:52
org.wpilib.math.geometry.Translation3d.Translation3d
Translation3d(Vector< N3 > vector)
Definition
Translation3d.java:113
org.wpilib.math.geometry.Translation3d.toTranslation2d
Translation2d toTranslation2d()
Definition
Translation3d.java:290
org.wpilib.math.geometry.Translation3d.getZ
double getZ()
Definition
Translation3d.java:171
org.wpilib.math.geometry.Translation3d.nearest
Translation3d nearest(Collection< Translation3d > translations)
Definition
Translation3d.java:360
org.wpilib.math.geometry.Translation3d.getSquaredNorm
double getSquaredNorm()
Definition
Translation3d.java:226
org.wpilib.math.geometry.Translation3d.getMeasureZ
Distance getMeasureZ()
Definition
Translation3d.java:198
org.wpilib.math.geometry.Translation3d.getY
double getY()
Definition
Translation3d.java:162
org.wpilib.math.geometry.Translation3d.getNorm
double getNorm()
Definition
Translation3d.java:216
org.wpilib.math.geometry.Translation3d.times
Translation3d times(double scalar)
Definition
Translation3d.java:338
org.wpilib.math.geometry.Translation3d.dot
double dot(Translation3d other)
Definition
Translation3d.java:264
org.wpilib.math.geometry.Translation3d.minus
Translation3d minus(Translation3d other)
Definition
Translation3d.java:316
org.wpilib.math.geometry.Translation3d.getDistance
double getDistance(Translation3d other)
Definition
Translation3d.java:125
org.wpilib.math.geometry.Translation3d.getX
double getX()
Definition
Translation3d.java:153
org.wpilib.math.geometry.Translation3d.Translation3d
Translation3d(Translation2d translation)
Definition
Translation3d.java:103
org.wpilib.math.geometry.Translation3d.Translation3d
Translation3d(Distance x, Distance y, Distance z)
Definition
Translation3d.java:92
org.wpilib.math.geometry.Translation3d.div
Translation3d div(double scalar)
Definition
Translation3d.java:350
org.wpilib.math.geometry.Translation3d.ZERO
static final Translation3d ZERO
Definition
Translation3d.java:40
org.wpilib.math.geometry.Translation3d.equals
boolean equals(Object obj)
Definition
Translation3d.java:376
org.wpilib.math.geometry.Translation3d.toVector
Vector< N3 > toVector()
Definition
Translation3d.java:207
org.wpilib.math.geometry.Translation3d.proto
static final Translation3dProto proto
Definition
Translation3d.java:397
org.wpilib.math.geometry.Translation3d.unaryMinus
Translation3d unaryMinus()
Definition
Translation3d.java:326
org.wpilib.math.geometry.proto.Translation3dProto
Definition
Translation3dProto.java:12
org.wpilib.math.geometry.struct.Translation3dStruct
Definition
Translation3dStruct.java:11
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.get
double get(int row)
Definition
Vector.java:67
org.wpilib.math.interpolation.Interpolatable
Definition
Interpolatable.java:15
org.wpilib.util.protobuf.ProtobufSerializable
Definition
ProtobufSerializable.java:16
org.wpilib.util.struct.StructSerializable
Definition
StructSerializable.java:16
org
wpilib
math
geometry
Translation3d.java
Generated by
1.18.0