-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed elliptical nosecone; added torus and tube primitives
- Loading branch information
Showing
8 changed files
with
195 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using System.IO; | ||
using Qkmaxware.Geometry; | ||
using Qkmaxware.Geometry.IO; | ||
using Qkmaxware.Geometry.Primitives; | ||
|
||
namespace Astro.Testing { | ||
|
||
[TestClass] | ||
public class TorusTest : PrimitiveTest { | ||
[TestMethod] | ||
public void TestTorus() { | ||
var geom = new Torus(1, 0.2, Vec3.Zero); | ||
SaveGeometry("torus", geom); | ||
} | ||
} | ||
|
||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using System.IO; | ||
using Qkmaxware.Geometry; | ||
using Qkmaxware.Geometry.IO; | ||
using Qkmaxware.Geometry.Primitives; | ||
|
||
namespace Astro.Testing { | ||
|
||
[TestClass] | ||
public class TubeTest : PrimitiveTest { | ||
[TestMethod] | ||
public void TestTube() { | ||
var geom = new Tube(1, 0.8, 2, Vec3.Zero); | ||
SaveGeometry("tube", geom); | ||
} | ||
} | ||
|
||
} |
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Qkmaxware.Geometry.Primitives { | ||
|
||
/// <summary> | ||
/// Torus mesh | ||
/// </summary> | ||
public class Torus : Mesh { | ||
|
||
public Torus (double majorRadius, double minorRadius, Vec3 centre, int resolution = 8, int segments = 8) { | ||
double ringStep = 2 * Math.PI / resolution; | ||
double moveStep = 2 * Math.PI / segments; | ||
|
||
for (int i = 1; i <= segments; i++) { | ||
double prevAngle = (i - 1) * moveStep; | ||
double angle = (i) * moveStep; | ||
|
||
var previousDirection = new Vec3( | ||
Math.Cos(prevAngle), | ||
Math.Sin(prevAngle), | ||
0 | ||
); | ||
var previousPointCentre = majorRadius * previousDirection + centre; | ||
var previousLeft = previousDirection; | ||
var previousUp = Vec3.K; | ||
|
||
var nextDirection = new Vec3( | ||
Math.Cos(angle), | ||
Math.Sin(angle), | ||
0 | ||
); | ||
var nextPointCentre = majorRadius * nextDirection + centre; | ||
var nextLeft = nextDirection; | ||
var nextUp = Vec3.K; | ||
|
||
// Move around the ring | ||
for (var j = 1; j <= resolution; j++) { | ||
double prevCicleAngle = (j - 1) * ringStep; | ||
double cicleAngle = (j) * ringStep; | ||
|
||
// Previous points | ||
var previousStart = previousPointCentre + minorRadius * ( previousLeft * Math.Cos(prevCicleAngle) + previousUp * Math.Sin(prevCicleAngle) ); | ||
var previousEnd = previousPointCentre + minorRadius * ( previousLeft * Math.Cos(cicleAngle) + previousUp * Math.Sin(cicleAngle) ); | ||
|
||
// Next points | ||
var nextStart = nextPointCentre + minorRadius * ( nextLeft * Math.Cos(prevCicleAngle) + nextUp * Math.Sin(prevCicleAngle) ); | ||
var nextEnd = nextPointCentre + minorRadius * ( nextLeft * Math.Cos(cicleAngle) + nextUp * Math.Sin(cicleAngle) ); | ||
|
||
// Create faces | ||
this.Append(new Triangle(previousStart, nextStart, nextEnd)); | ||
this.Append(new Triangle(previousStart, nextEnd, previousEnd)); | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Qkmaxware.Geometry.Primitives { | ||
|
||
/// <summary> | ||
/// Tube mesh | ||
/// </summary> | ||
public class Tube : Mesh { | ||
private static List<Triangle> Generate(double outerRadius, double innerRadius, double h, Vec3 centre, int resolution) { | ||
List<Triangle> triangles = new List<Triangle>(); | ||
double step = 2 * Math.PI / resolution; | ||
double hStep = h / 2; | ||
|
||
for (int i = 1; i <= resolution; i++) { | ||
double prevAngle = (i - 1) * step; | ||
double xi = Math.Cos(prevAngle); | ||
double yi = Math.Sin(prevAngle); | ||
|
||
double angle = i * step; | ||
double xe = Math.Cos(angle); | ||
double ye = Math.Sin(angle); | ||
|
||
/* | ||
top | ||
/ \ | ||
te -- ti | ||
| / | | ||
| / | | ||
be -- bi | ||
\ / | ||
bottom | ||
*/ | ||
// Outer tube | ||
// Create top points | ||
Vec3 te = new Vec3(xe * outerRadius, ye * outerRadius, hStep) + centre; | ||
Vec3 ti = new Vec3(xi * outerRadius, yi * outerRadius, hStep) + centre; | ||
// Create bottom points | ||
Vec3 be = new Vec3(xe * outerRadius, ye * outerRadius, -hStep) + centre; | ||
Vec3 bi = new Vec3(xi * outerRadius, yi * outerRadius, -hStep) + centre; | ||
|
||
// Create triangles | ||
triangles.Add(new Triangle(be, te, ti)); | ||
triangles.Add(new Triangle(be, ti, bi)); | ||
|
||
// Inner tube | ||
// Create top points | ||
Vec3 ite = new Vec3(xe * innerRadius, ye * innerRadius, hStep) + centre; | ||
Vec3 iti = new Vec3(xi * innerRadius, yi * innerRadius, hStep) + centre; | ||
// Create bottom points | ||
Vec3 ibe = new Vec3(xe * innerRadius, ye * innerRadius, -hStep) + centre; | ||
Vec3 ibi = new Vec3(xi * innerRadius, yi * innerRadius, -hStep) + centre; | ||
|
||
// Create triangles | ||
triangles.Add(new Triangle(ibe, iti, ite)); | ||
triangles.Add(new Triangle(ibe, ibi, iti)); | ||
|
||
// Joiners | ||
triangles.Add(new Triangle(te, ite, iti)); | ||
triangles.Add(new Triangle(te, iti, ti)); | ||
|
||
triangles.Add(new Triangle(be, ibi, ibe)); | ||
triangles.Add(new Triangle(be, bi, ibi)); | ||
} | ||
|
||
return triangles; | ||
} | ||
|
||
/// <summary> | ||
/// Cylinder with different radii for top and bottom caps | ||
/// </summary> | ||
/// <param name="outerRadius">outer radius</param> | ||
/// <param name="innerRadius">inner radius</param> | ||
/// <param name="height">height</param> | ||
/// <param name="centre">centre</param> | ||
/// <param name="resolution">subdivision level</param> | ||
public Tube (double outerRadius, double innerRadius, double height, Vec3 centre, int resolution = 8) : base(Generate(outerRadius, innerRadius, height, centre, resolution)) {} | ||
|
||
|
||
} | ||
|
||
} |
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.