-
Notifications
You must be signed in to change notification settings - Fork 1
Draft of displaced center. #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nicolau-manubens
wants to merge
7
commits into
dvuckovic:main
Choose a base branch
from
nicolau-manubens:develop-displaced-center
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0b21a2d
Draft of displaced center.
886ed7f
Fix comments in Main.vue
nicolau-manubens b3a4e60
Extended input range component so it can handle floats too.
dvuckovic a375c49
Merge branch 'main' into develop-displaced-center
dvuckovic fce48f3
Merge branch 'main' into develop-displaced-center
dvuckovic 24e3e20
Merge branch 'main' into develop-displaced-center
dvuckovic d0bf5fb
Merge branch 'main' into develop-displaced-center
dvuckovic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,6 +95,26 @@ | |
| label="Second step" /> | ||
| </div> | ||
| </div> | ||
| <div class="row"> | ||
| <div class="col"> | ||
| <InputRange | ||
| v-model="paramX" | ||
| v-bind:min="-0.99" | ||
| v-bind:max="0.99" | ||
| setp="0.01" | ||
| label="Center X displacement" /> | ||
| </div> | ||
| </div> | ||
| <div class="row"> | ||
| <div class="col"> | ||
| <InputRange | ||
| v-model="paramY" | ||
| v-bind:min="-0.99" | ||
| v-bind:max="0.99" | ||
| setp="0.01" | ||
| label="Center Y displacement" /> | ||
| </div> | ||
| </div> | ||
| <div class="row my-3 justify-content-between"> | ||
| <div class="col-12 col-xxl-4 order-3 order-xxl-1 mt-3 d-grid"> | ||
| <button | ||
|
|
@@ -176,6 +196,8 @@ const DEFAULT = { | |
| PARAM_C_MULTIPLE: colors, | ||
| PARAM_N1: 1, | ||
| PARAM_N2: 3, | ||
| PARAM_X: 0.5, | ||
| PARAM_Y: 0.0, | ||
| WIDTH: 1024, | ||
| HEIGHT: 768, | ||
| }; | ||
|
|
@@ -202,6 +224,8 @@ export default { | |
| }, | ||
| paramN1: DEFAULT.PARAM_N1, | ||
| paramN2: DEFAULT.PARAM_N2, | ||
| paramX: DEFAULT.PARAM_X, | ||
| paramY: DEFAULT.PARAM_Y, | ||
| width: DEFAULT.WIDTH, | ||
| height: DEFAULT.HEIGHT, | ||
| cx: parseInt(DEFAULT.WIDTH / 2, 10), | ||
|
|
@@ -213,18 +237,60 @@ export default { | |
|
|
||
| computed: { | ||
| circlePoints () { | ||
| const n = this.paramN; | ||
| const alpha = Math.PI * 2 / n; | ||
| const points = []; | ||
| // method: drawing two circles, the first centered in (0, 0) and | ||
| // the second centered at (x_offset, y_offset). | ||
| // For each point in the upper semicircle of the first circle, we draw | ||
| // a line joining that point with (0, 0), and intersect such line with the | ||
| // displaced circle | ||
|
|
||
| let i = -1; | ||
| const n_points = this.paramN; | ||
| const r = 1.0; | ||
|
|
||
| while (i < n) { | ||
| const theta = alpha * i; | ||
| // find formula of second circle (x - h) ^ 2 + (y - k) ^ 2 = r ^ 2 | ||
| const h = this.paramX; | ||
| const k = this.paramY; | ||
|
|
||
| const alpha = Math.PI * 2 / n_points; | ||
| const points = []; | ||
|
|
||
| // loop all points of the top half of the first circle | ||
| // TODO: the previous loop was ranging from -1 to n-1 and adding a point each iteration (total of n+1 points) | ||
| // whereas the current is ranging from 0 to n/2 and adding two points each iteration | ||
| // (total of n+2 if n is even, n+1 if n is odd) | ||
| let i = 0; | ||
| while (i <= n_points / 2) { | ||
| const theta = alpha * i; | ||
| const xc1 = Math.cos(theta) * r; | ||
| const yc2 = Math.sin(theta) * r; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This variable is unused?! |
||
|
|
||
| // for each point, find line y = m*x + n passing by (0,0) and (x,y) | ||
| const n = 0; | ||
| const m = (yc1 - n) / xc1; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| // and find both intersections of such line with the second circle | ||
| // { (x - h) ^ 2 + (y - k) ^ 2 = r ^ 2 | ||
| // { y = m * x + n | ||
| // ----------------------------------- | ||
| // (1 + m^2) * x^2 + (2mn - 2h - 2mk) * x + (h^2 + n^2 + k^2 - r^2 - 2nk) = 0 | ||
| const a = 1 + Math.pow(m, 2); | ||
| const b = 2 * m * n - 2 * h - 2 * m * k; | ||
| const c = Math.pow(h, 2) + Math.pow(n, 2) + Math.pow(k, 2) - Math.pow(r, 2) - 2 * n * k; | ||
| const x1 = (0 - b + Math.sqrt(Math.pow(b, 2) - 4 * a * c) ) / (2 * a); | ||
| const x2 = (0 - b - Math.sqrt(Math.pow(b, 2) - 4 * a * c) ) / (2 * a); | ||
| const y1 = m * x1 + n; | ||
| const y2 = m * x2 + n; | ||
|
|
||
| // recenter second circle to (0, 0) and store the intersections found in that circle | ||
| // scale the points according to rad | ||
| // recenter second circle to (cx, cy) | ||
| // store the points | ||
| points.push({ | ||
| x: (Math.cos(theta) * this.rad) + this.cx, | ||
| y: (Math.sin(theta) * this.rad) + this.cy, | ||
| x: (x1 - h) * this.rad + this.cx, | ||
| y: (y1 - k) * this.rad + this.cy, | ||
| }); | ||
| points.push({ | ||
| x: (x2 - h) * this.rad + this.cx, | ||
| y: (y2 - k) * this.rad + this.cy, | ||
| }); | ||
|
|
||
| i += 1; | ||
|
|
@@ -283,6 +349,8 @@ export default { | |
| paramC: this.paramC, | ||
| paramN1: this.paramN1, | ||
| paramN2: this.paramN2, | ||
| paramX: this.paramX, | ||
| paramY: this.paramY, | ||
| }; | ||
| }, | ||
|
|
||
|
|
@@ -326,6 +394,14 @@ export default { | |
| paramM () { | ||
| this.$nextTick(() => this.drawCanvas()); | ||
| }, | ||
|
|
||
| paramX () { | ||
| this.$nextTick(() => this.drawCanvas()); | ||
| }, | ||
|
|
||
| paramY () { | ||
| this.$nextTick(() => this.drawCanvas()); | ||
| }, | ||
| }, | ||
|
|
||
| mounted () { | ||
|
|
@@ -361,6 +437,8 @@ export default { | |
| this.paramC = data.paramC; | ||
| this.paramN1 = data.paramN1; | ||
| this.paramN2 = data.paramN2; | ||
| this.paramX = data.paramX; | ||
| this.paramY = data.paramY; | ||
| this.isModified = false; | ||
| }, | ||
|
|
||
|
|
@@ -392,6 +470,8 @@ export default { | |
| }, | ||
| paramN1: DEFAULT.PARAM_N1, | ||
| paramN2: DEFAULT.PARAM_N2, | ||
| paramX: DEFAULT.PARAM_X, | ||
| paramY: DEFAULT.PARAM_Y, | ||
| }); | ||
| }, | ||
|
|
||
|
|
@@ -456,4 +536,4 @@ main { | |
| border-radius: 0.25rem; | ||
| } | ||
| } | ||
| </style> | ||
| </style> | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
circlePointscomputed property should return circle points sorted in logical order, becauselinePointsdepends on that. At the moment the final result is somewhat unexpected, because lines are not correctly drawn. You can check this out by running the generator on the unmodified code, and then comparing its output with your branch, when the center x/y displacement is 0/0 (should result in the same image).