Last active
November 13, 2017 07:16
-
-
Save bradphelan/d63f6993febf4d9edd9729738ddd2ba4 to your computer and use it in GitHub Desktop.
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
using devDept.Eyeshot.Entities; | |
using devDept.Geometry; | |
using ReactiveUI; | |
using System; | |
using System.Drawing; | |
using System.Reactive.Linq; | |
using System.Runtime.CompilerServices; | |
using Weingartner.EyeshotExtensions; | |
using Weingartner.EyeshotExtensions.Assembly3D; | |
namespace Weingartner.Numerics.Gearing | |
{ | |
public class SpurGearAnimator : Assembly3D | |
{ | |
public Gear Gears {get; private set;} | |
private readonly Assembly3D _GearAEntity; | |
private readonly Assembly3D _GearBEntity; | |
public double Excenter => Gears.A.PitchRadius + Gears.B.PitchRadius; | |
private double _Angle; | |
public double Angle | |
{ | |
get => _Angle; | |
set => this.RaiseAndSetIfChanged(ref _Angle, value); | |
} | |
public double FullSweepAngle => 2 * Math.PI * Gears.B.Teeth / Gears.A.Teeth; | |
public SpurGearAnimator(Gear gear,[CallerFilePath] string path = "", [CallerLineNumber] int line = 0):base(path,line) | |
{ | |
Gears = gear; | |
_GearAEntity = BuildGearEntity(Gears.GearACurve(),Gears.A, Color.Red); | |
_GearBEntity = BuildGearEntity(Gears.GearBCurve(),Gears.B, Color.Green); | |
var rotationA = (Transformation) new Rotation(0, Vector3D.AxisZ); | |
var rotationB = (Transformation) new Rotation(- Math.PI , Vector3D.AxisZ); | |
var translationB = new Transformation(); | |
translationB.Translation(Vector3D.AxisX*(Gears.A.PitchRadius+Gears.B.PitchRadius)); | |
rotationB = translationB * rotationB; | |
_GearBEntity.Transformation = rotationB; | |
_GearAEntity.Transformation = rotationA; | |
this.WhenAnyValue(p => p.Angle) | |
.Select(angle => rotationA * new Rotation(angle, Vector3D.AxisZ)) | |
.BindTo(this, p => p._GearAEntity.Transformation); | |
this.WhenAnyValue(p => p.Angle) | |
.Select(angle => -angle * Gears.A.Teeth / Gears.B.Teeth) | |
.Select(angle => rotationB * new Rotation(angle, Vector3D.AxisZ)) | |
.BindTo(this, p => p._GearBEntity.Transformation); | |
Add(_GearAEntity); | |
Add(_GearBEntity); | |
} | |
private static Assembly3D BuildGearEntity | |
( CompositeCurve gearCurve | |
, GearParameters gear, Color? colorp = null) | |
{ | |
var color = colorp ?? Color.Silver; | |
gearCurve.SetColorAndWeight( color, 3 ); | |
var be = new Assembly3D(); | |
be.Add(gear.MajorCurve()); | |
//be.Add(spur.BaseCurve()); | |
be.Add(gear.PitchCurve()); | |
var l = 2 * gear.MajorRadius / 10; | |
var l0 = new Line(0, -l, 0, l); | |
var l1 = new Line(-l, 0, l, 0); | |
var c = new Circle(Plane.XY, l * 3 / 4); | |
be.Add(l0); | |
be.Add(l1); | |
be.Add(c); | |
be.Add(gearCurve); | |
return be; | |
} | |
} | |
} |
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
[WpfFact] | |
public void DrawCounterPart() | |
{ | |
var spurFlankA = new SpurGearFlank | |
( pressureAngle: 27 * Math.PI / 180 | |
, flankGap: 0 | |
); | |
var straightFlank = new StraightFlank | |
( pressureAngle: 45 * Math.PI / 180 | |
, flankGap: 5e-3 | |
); | |
var gear = new Gear | |
( teethA: 10 | |
, teethB: 15 | |
, bottomGap: 0e-3 | |
, module: 0.1 /10 | |
, topFlank: spurFlankA | |
, bottomFlank: spurFlankA | |
, addendumA: 10e-3 | |
, addendumB: 10e-3 | |
); | |
var animator = new SpurGearAnimator(gear); | |
Observable.Interval(TimeSpan.FromSeconds(1 / 25.0), AssemblyLogger.ModelInstance.Scheduler) | |
.Select(i => (i % 500) / 500.0 * animator.FullSweepAngle) | |
.BindTo(animator, p => p.Angle); | |
animator.Log("Spur Gear").Wait(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment