Skip to content
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

feat: Add ability to draw 3d circles #6

Open
mithi opened this issue Aug 30, 2020 · 4 comments
Open

feat: Add ability to draw 3d circles #6

mithi opened this issue Aug 30, 2020 · 4 comments

Comments

@mithi
Copy link
Owner

mithi commented Aug 30, 2020

Algorithm

  1. Start with a 2d circle defined by a radius, centered at the origin, in the xy plane
  2. Get 5 points of a circle(r, 0), (-r, 0), (0, r), (0, -r), (0, 0)
  3. Transform these 5 points in 3d given the 3 euler angles and the actual center (x, y, z)
  4. Convert these points into 2d by projecting it to the canvas, the circle is now and ellipse
  5. Get the radiusX and radiusY of the ellipse given the origin and two of the transformed points (compute the distance)
  6. Get the angle of this new ellipse by getting the dot product of one of the vectors formed by the origin and one of the points and the x axis
  7. We have now defined the ellipse (2d center, radiusX, radiusY, angle) representation
@fuddl
Copy link
Contributor

fuddl commented Mar 27, 2022

For anyone interested: You can draw an approximation of a circle using the QuadraticBezier plugin:

const precision = 42;

let circleXYPoints = {
  x: [],
  y: [],
  z: [],
}

for (let i = 0; i <= Math.PI * 2; i = i + (Math.PI / precision)) {
  circleXYPoints.x.push(Math.cos(i) * r);
  circleXYPoints.y.push(Math.sin(i) * r);
  circleXYPoints.z.push(0);
}

points.push({
  id: 'circle',
  type: 'QuadraticBezier',
  color: 'red',
  ...circleXYPoints,
});

@mithi
Copy link
Owner Author

mithi commented Mar 28, 2022

Hi @fuddl , thanks your the input, here's the plugin if anyone's interested:
https://github.com/fuddl/bare-minimum-quadratic-bezier

it would be nice if it's possible to draw circles that are "angled" in 3d space, circles which are not parallel to the x, y, or z planes. 😄

@fuddl
Copy link
Contributor

fuddl commented Mar 28, 2022

I will have to think about it

@mithi
Copy link
Owner Author

mithi commented Mar 29, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants