Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
node-drone
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
15김건우
node-drone
Commits
60b3c621
Commit
60b3c621
authored
Jun 07, 2019
by
16김민성
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add vector library
parent
655e8293
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
97 additions
and
0 deletions
+97
-0
possys.js
public/possys.js
+97
-0
No files found.
public/possys.js
0 → 100644
View file @
60b3c621
/* Convert sphere coordinate system to rectangular coordinate system
* x = r * sin(theta) * cos(phi)
* y = r * sin(theta) * sin(phi)
* z = r * cos(theta)
*/
/* Reverse conversion
* r = sqrt(x*x + y*y + z*z)
* theta = acos(z/r)
* phi = atan(y/x)
*/
/* A vector library written by 'evanw'; source: https://evanw.github.io/lightgl.js/docs/vector.html */
function
Vector
(
x
,
y
,
z
)
{
this
.
x
=
x
||
0
;
this
.
y
=
y
||
0
;
this
.
z
=
z
||
0
;
}
Vector
.
prototype
=
{
negative
:
function
()
{
return
new
Vector
(
-
this
.
x
,
-
this
.
y
,
-
this
.
z
);
},
add
:
function
(
v
)
{
if
(
v
instanceof
Vector
)
return
new
Vector
(
this
.
x
+
v
.
x
,
this
.
y
+
v
.
y
,
this
.
z
+
v
.
z
);
else
return
new
Vector
(
this
.
x
+
v
,
this
.
y
+
v
,
this
.
z
+
v
);
},
subtract
:
function
(
v
)
{
if
(
v
instanceof
Vector
)
return
new
Vector
(
this
.
x
-
v
.
x
,
this
.
y
-
v
.
y
,
this
.
z
-
v
.
z
);
else
return
new
Vector
(
this
.
x
-
v
,
this
.
y
-
v
,
this
.
z
-
v
);
},
multiply
:
function
(
v
)
{
if
(
v
instanceof
Vector
)
return
new
Vector
(
this
.
x
*
v
.
x
,
this
.
y
*
v
.
y
,
this
.
z
*
v
.
z
);
else
return
new
Vector
(
this
.
x
*
v
,
this
.
y
*
v
,
this
.
z
*
v
);
},
divide
:
function
(
v
)
{
if
(
v
instanceof
Vector
)
return
new
Vector
(
this
.
x
/
v
.
x
,
this
.
y
/
v
.
y
,
this
.
z
/
v
.
z
);
else
return
new
Vector
(
this
.
x
/
v
,
this
.
y
/
v
,
this
.
z
/
v
);
},
equals
:
function
(
v
)
{
return
this
.
x
==
v
.
x
&&
this
.
y
==
v
.
y
&&
this
.
z
==
v
.
z
;
},
dot
:
function
(
v
)
{
return
this
.
x
*
v
.
x
+
this
.
y
*
v
.
y
+
this
.
z
*
v
.
z
;
},
cross
:
function
(
v
)
{
return
new
Vector
(
this
.
y
*
v
.
z
-
this
.
z
*
v
.
y
,
this
.
z
*
v
.
x
-
this
.
x
*
v
.
z
,
this
.
x
*
v
.
y
-
this
.
y
*
v
.
x
);
},
length
:
function
()
{
return
Math
.
sqrt
(
this
.
dot
(
this
));
},
unit
:
function
()
{
return
this
.
divide
(
this
.
length
());
},
min
:
function
()
{
return
Math
.
min
(
Math
.
min
(
this
.
x
,
this
.
y
),
this
.
z
);
},
max
:
function
()
{
return
Math
.
max
(
Math
.
max
(
this
.
x
,
this
.
y
),
this
.
z
);
},
toAngles
:
function
()
{
return
{
theta
:
Math
.
atan2
(
this
.
z
,
this
.
x
),
phi
:
Math
.
asin
(
this
.
y
/
this
.
length
())
};
},
angleTo
:
function
(
a
)
{
return
Math
.
acos
(
this
.
dot
(
a
)
/
(
this
.
length
()
*
a
.
length
()));
},
toArray
:
function
(
n
)
{
return
[
this
.
x
,
this
.
y
,
this
.
z
].
slice
(
0
,
n
||
3
);
},
clone
:
function
()
{
return
new
Vector
(
this
.
x
,
this
.
y
,
this
.
z
);
},
init
:
function
(
x
,
y
,
z
)
{
this
.
x
=
x
;
this
.
y
=
y
;
this
.
z
=
z
;
return
this
;
}
};
var
distHand
=
80
;
var
distDrone
=
500
;
var
origin
=
Vector
(
0
,
0
,
0
);
var
posHand
=
Vector
(
80
,
0
,
0
);
var
posDrone
=
Vector
(
500
,
0
,
0
);
function
handToDroneDelta
(
_nextHand
){
var
delta
=
_nextHand
-
origin
;
delta
=
delta
.
multiply
()
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment