Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
computergrafik-03
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Temple
computergrafik-03
Commits
53f28977
Unverified
Commit
53f28977
authored
3 years ago
by
Jamie Temple
Browse files
Options
Downloads
Patches
Plain Diff
feat: interpolation
parent
9653ab1a
No related branches found
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
Main.cpp
+9
-0
9 additions, 0 deletions
Main.cpp
Main.exe
+0
-0
0 additions, 0 deletions
Main.exe
Main.obj
+0
-0
0 additions, 0 deletions
Main.obj
src/main.ts
+8
-8
8 additions, 8 deletions
src/main.ts
src/uitls/bezierCurve.ts
+101
-28
101 additions, 28 deletions
src/uitls/bezierCurve.ts
with
118 additions
and
36 deletions
Main.cpp
0 → 100644
+
9
−
0
View file @
53f28977
#include
<iostream>
int
main
(
void
)
{
for
(
double
i
{
0
};
i
<
1
;
i
+=
0.1
)
{
std
::
cout
<<
i
<<
", "
<<
i
*
i
<<
std
::
endl
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Main.exe
0 → 100644
+
0
−
0
View file @
53f28977
File added
This diff is collapsed.
Click to expand it.
Main.obj
0 → 100644
+
0
−
0
View file @
53f28977
File added
This diff is collapsed.
Click to expand it.
src/main.ts
+
8
−
8
View file @
53f28977
import
*
as
CG
from
"
./uitls/rendering
"
;
import
*
as
THREE
from
"
three
"
;
import
{
UI
}
from
"
./uitls/ui
"
;
import
{
Vector3
}
from
"
three
"
;
import
*
as
Interpolation
from
"
./uitls/bezierCurve
"
;
const
render
=
new
CG
.
RenderManager
(
'
#canvas
'
,
{
near
:
0.1
,
far
:
1000
,
fov
:
45
,
height
:
1
});
const
ui
=
new
UI
();
// create a cube
let
geometry
=
new
THREE
.
BoxGeometry
(
1
,
1
,
1
);
let
material
=
new
THREE
.
MeshBasicMaterial
({
color
:
0xfffffff
});
let
cube
=
new
THREE
.
Mesh
(
geometry
,
material
);
// render.add(cube);
const
startPoint
=
new
THREE
.
Vector2
(
-
1
,
-
1
);
const
endPoint
=
new
THREE
.
Vector2
(
1
,
1
);
const
startControlPoint
=
new
THREE
.
Vector2
(
-
1
,
1
);
const
endControlPoint
=
new
THREE
.
Vector2
(
1
,
-
1
);
const
curve
=
new
Interpolation
.
BezierCurveTest
(
// const curve = new Interpolation.BezierCurveTest(
// startPoint,
// startControlPoint,
// endControlPoint,
// endPoint
// )
const
curve
=
new
Interpolation
.
BezierCurve
(
startPoint
,
endPoint
,
startControlPoint
,
endControlPoint
)
const
line
=
curve
.
createLine
();
render
.
add
(
line
);
...
...
This diff is collapsed.
Click to expand it.
src/uitls/bezierCurve.ts
+
101
−
28
View file @
53f28977
...
...
@@ -9,13 +9,17 @@ import {
}
from
"
three
"
;
import
{
GUI
}
from
"
dat.gui
"
;
function
lerp
(
a
:
Vector2
,
b
:
Vector2
,
t
:
number
):
Vector2
{
return
new
Vector2
(
a
.
x
+
(
b
.
x
-
a
.
x
)
*
t
,
a
.
y
+
(
b
.
y
-
a
.
y
)
*
t
);
}
export
abstract
class
AbstractBezierCurve
implements
Modifiable
,
Updatable
{
constructor
(
startPoint
:
Vector2
,
endPoint
:
Vector2
,
startControlPoint
:
Vector2
,
endControlPoint
:
Vector2
)
{
this
.
_
startPoint
=
startPoint
;
this
.
_
endPoint
=
endPoint
;
this
.
_
startControlPoint
=
startControlPoint
;
this
.
_
endControlPoint
=
endControlPoint
;
this
.
startPoint
=
startPoint
;
this
.
endPoint
=
endPoint
;
this
.
startControlPoint
=
startControlPoint
;
this
.
endControlPoint
=
endControlPoint
;
this
.
_geomBuffer
=
new
BufferGeometry
();
}
...
...
@@ -44,22 +48,24 @@ export abstract class AbstractBezierCurve implements Modifiable, Updatable {
createElement
(
gui
:
GUI
):
void
{
const
folder
=
gui
.
addFolder
(
'
Bezier Curve
'
);
UI
.
addVector
(
folder
,
this
,
this
.
_
startPoint
,
'
Start Point
'
);
UI
.
addVector
(
folder
,
this
,
this
.
_
endPoint
,
'
End Point
'
);
UI
.
addVector
(
folder
,
this
,
this
.
_
startControlPoint
,
'
Start Control Point
'
);
UI
.
addVector
(
folder
,
this
,
this
.
_
endControlPoint
,
'
End Control Point
'
);
UI
.
addVector
(
folder
,
this
,
this
.
startPoint
,
'
Start Point
'
);
UI
.
addVector
(
folder
,
this
,
this
.
endPoint
,
'
End Point
'
);
UI
.
addVector
(
folder
,
this
,
this
.
startControlPoint
,
'
Start Control Point
'
);
UI
.
addVector
(
folder
,
this
,
this
.
endControlPoint
,
'
End Control Point
'
);
folder
.
add
(
this
,
"
_numPoints
"
,
10
,
100
).
step
(
1
).
name
(
"
Points
"
).
onChange
(()
=>
{
this
.
update
();
});
}
public
_startPoint
:
Vector2
;
public
_endPoint
:
Vector2
;
public
_startControlPoint
:
Vector2
;
public
_endControlPoint
:
Vector2
;
public
_numPoints
:
number
=
100
;
public
_line
?:
Line
;
public
_curvePoints
:
Vector2
[]
=
[];
public
_geomBuffer
:
BufferGeometry
;
public
startPoint
:
Vector2
;
public
endPoint
:
Vector2
;
public
startControlPoint
:
Vector2
;
public
endControlPoint
:
Vector2
;
protected
_numPoints
:
number
=
100
;
private
_line
?:
Line
;
private
_curvePoints
:
Vector2
[]
=
[];
private
_geomBuffer
:
BufferGeometry
;
}
// TODO: Handles for the control points
...
...
@@ -81,10 +87,10 @@ export class BezierCurveTest extends AbstractBezierCurve {
generateCurvePoints
():
Vector2
[]
{
const
curve
=
new
CubicBezierCurve3
(
new
Vector3
(
this
.
_
startPoint
.
x
,
this
.
_
startPoint
.
y
,
0
),
new
Vector3
(
this
.
_
startControlPoint
.
x
,
this
.
_
startControlPoint
.
y
,
0
),
new
Vector3
(
this
.
_
endPoint
.
x
,
this
.
_
endPoint
.
y
,
0
),
new
Vector3
(
this
.
_
endControlPoint
.
x
,
this
.
_
endControlPoint
.
y
,
0
)
new
Vector3
(
this
.
startPoint
.
x
,
this
.
startPoint
.
y
,
0
),
new
Vector3
(
this
.
startControlPoint
.
x
,
this
.
startControlPoint
.
y
,
0
),
new
Vector3
(
this
.
endPoint
.
x
,
this
.
endPoint
.
y
,
0
),
new
Vector3
(
this
.
endControlPoint
.
x
,
this
.
endControlPoint
.
y
,
0
)
);
let
curvePoints
:
Vector2
[]
=
[];
...
...
@@ -100,10 +106,77 @@ export class BezierCurveTest extends AbstractBezierCurve {
export
class
BezierCurve
extends
AbstractBezierCurve
{
bernstain
(
s
:
number
):
[
Vector2
,
number
[]]
{
// p(t) = (1-t)³ * p0 + 3 * (1-t)² * t * p1 +
// 3 * (1-t) * t² * p2 + t³ * p3
// => subtitute: 1 - t = s
// p(t) = k³ * p0 + 3 * k² * t * p1 +
// 3 * k * t² * p2 + t³ * p3
const
p0
=
this
.
startPoint
;
const
p1
=
this
.
startControlPoint
;
const
p2
=
this
.
endControlPoint
;
const
p3
=
this
.
endPoint
;
// set k = 1 - s => substitution
const
t
=
s
;
const
k
=
1
-
s
;
// calculate the coefficients
const
u0
=
1
*
Math
.
pow
(
k
,
3
)
*
Math
.
pow
(
t
,
0
);
const
u1
=
3
*
Math
.
pow
(
k
,
2
)
*
Math
.
pow
(
t
,
1
);
const
u2
=
3
*
Math
.
pow
(
k
,
1
)
*
Math
.
pow
(
t
,
2
);
const
u3
=
1
*
Math
.
pow
(
k
,
0
)
*
Math
.
pow
(
t
,
3
);
// calculate the point
const
p
=
new
Vector2
(
u0
*
p0
.
x
+
u1
*
p1
.
x
+
u2
*
p2
.
x
+
u3
*
p3
.
x
,
u0
*
p0
.
y
+
u1
*
p1
.
y
+
u2
*
p2
.
y
+
u3
*
p3
.
y
);
return
[
p
,
[
u0
,
u1
,
u2
,
u3
]];
}
deCasteljau
(
t
:
number
):
Vector2
{
const
p0
=
this
.
startPoint
;
const
p1
=
this
.
startControlPoint
;
const
p2
=
this
.
endControlPoint
;
const
p3
=
this
.
endPoint
;
// iterative implementation of deCasteljau
let
points
:
Vector2
[]
=
[
p0
,
p1
,
p2
,
p3
];
let
temporary
:
Vector2
[]
=
[];
while
(
points
.
length
>
1
)
{
temporary
=
[];
for
(
let
i
=
0
;
i
<
points
.
length
-
1
;
i
++
)
temporary
.
push
(
lerp
(
points
[
i
],
points
[
i
+
1
],
t
));
points
=
temporary
;
}
return
points
[
0
];
}
generateCurvePoints
():
Vector2
[]
{
let
curvePoints
:
Vector2
[]
=
[];
const
curvePoints
:
Vector2
[]
=
[];
const
sampleSize
=
1
/
this
.
_numPoints
;
if
(
true
)
for
(
let
t
=
0
;
t
<
1
;
t
+=
sampleSize
)
{
t
=
Math
.
round
(
t
*
10000
)
/
10000
;
curvePoints
.
push
(
this
.
deCasteljau
(
t
));
}
else
for
(
let
s
=
0
;
s
<
1
;
s
+=
sampleSize
)
{
s
=
Math
.
round
(
s
*
10000
)
/
10000
;
const
[
point
,
coefficient
]
=
this
.
bernstain
(
s
);
curvePoints
.
push
(
point
);
}
// TODO: implement bezier curves
return
curvePoints
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment