Mathics3 / mathics-django

Django front-end to Mathics
Other
102 stars 11 forks source link

threejs 3D Rendering of (planar) Polygons #70

Open rocky opened 3 years ago

rocky commented 3 years ago
Graphics3D[
  Polygon[{
    {0, 0, Sqrt[3]},
    {0, 2 Sqrt[2/3], 1 / Sqrt[3]},
    {Sqrt[2], Sqrt[2/3], -1 / Sqrt[3]},
    {Sqrt[2], -Sqrt[2/3], 1 /  Sqrt[3]},
    {0, -2 Sqrt[2/3], -1 / Sqrt[3]},
    {-Sqrt[2], -Sqrt[2/3], 1/Sqrt[3]},
    {-Sqrt[2], Sqrt[2/3], -1/Sqrt[3]}
    }]]

should be a hexagon and slanted.

Graphics3D[Polygon[{{150,0, 0},{121,90, 0},{198,35, 0},{102,35, 0},{179,90, 0}}]]

should be a 5-pointed start with a hole for interior pentagon.

TiagoCavalcante commented 3 years ago
Graphics3D[
  Polygon[{
  {0, 0, Sqrt[3]},
  {0, 2 Sqrt[2/3], 1 / Sqrt[3]},
  {Sqrt[2], Sqrt[2/3], -1 / Sqrt[3]},
  {Sqrt[2], -Sqrt[2/3], 1 /  Sqrt[3]},
  {0, -2 Sqrt[2/3], -1 / Sqrt[3]},
  {-Sqrt[2], -Sqrt[2/3], 1/Sqrt[3]},
  {-Sqrt[2], Sqrt[2/3], -1/Sqrt[3]}
    }]]

should be a hexagon and slanted.

@rocky I already tried to draw non coplanar polygons and I could only do it with 500 lines of code, I guess that maybe we should keep the behavior of WL.

Graphics3D[Polygon[{{150,0, 0},{121,90, 0},{198,35, 0},{102,35, 0},{179,90, 0}}]]

should be a 5-pointed start with a hole for interior pentagon.

This [I guess] is possible to be done in WL, but also polygons with holes is very hard in three.js.

@rocky maybe we should focus in draw coplanar polygons first?

rocky commented 3 years ago

Would using the js earcut library help?

TiagoCavalcante commented 3 years ago

@rocky I used this library, for this works completely for non triangular polygons it's just necessary to convert Cuboid to draw cubes (this library doesn't draw triangular polygons correctly).

But for polygons with holes not specied it doesn't works.

But this fix the coplanar polygons problem.

Also, as we could add an if to toggle the library use, performance bottleneck won't be a problem.

I just said what I did because of I was wondering if we should add more one dependency. But after the Cuboid be converted to draw cube I can do it.

rocky commented 3 years ago

@TiagoCavalcanteTrindade Ok - thanks for the information.

I am for adding the dependency, especially since it seems to be pure JavaScript. And we just removed the dependency on scriptaculous.

We can wait for coplanar to work and get help on the Mathics-core side of things for holes.

If you think it helps for performance or want to try it, my opinion is go ahead. If on the other hand you don't want to go this route, that's fine too. You are probably in the best position to decide this.

TiagoCavalcante commented 3 years ago

I am for adding the dependency, especially since it seems to be pure JavaScript. And we just removed the dependency on scriptaculous.

@rocky it's still there, I just deleted some files, the main file was split into multiple ones because of a bug in Opera.

Also @rocky I'll go ahead, I just want to reformat the code and remove the dependency on prototype before.

But the performance will fall for the coplanar polygons (at least for the ones with the z axis always 0).