public GeometryModel3D GetShape(ScalingFactors scalingFactors)
        {
            GeometryModel3D      model           = new GeometryModel3D();
            ModelTransformations transformations = new Model.ModelTransformations();

            Point[] edgePoints = PlotUtilities.CalcEdgePoints(scalingFactors, slope, yIntercept);
            Point   midpoint   = PlotUtilities.CalculateMidpoint(edgePoints[0], edgePoints[1]);

            double length        = PlotUtilities.CalculateLength(edgePoints);
            double rotationAngle = PlotUtilities.CalcRotationAngle(slope);
            double yScaleFactor  = PlotUtilities.CalcYObjectScaleFactor(scalingFactors, rotationAngle);

            transformations.scale((length / 2), yScaleFactor);
            transformations.rotate(rotationAngle);
            transformations.translate(midpoint.X, midpoint.Y);

            model.Material  = new DiffuseMaterial(Brushes.Green);
            model.Geometry  = StandardSquare.CreateSquare();
            model.Transform = transformations.getTransformations();
            return(model);
        }
Beispiel #2
0
        public GeometryModel3D GetShape(ScalingFactors scalingFactors)
        {
            GeometryModel3D      model           = new GeometryModel3D();
            ModelTransformations transformations = new ModelTransformations();

            double slope = PlotUtilities.CalculateSlope(x1, y1, x2, y2);
            double yInt;

            Point[] edgePoints;
            //Length of Line from canvas edge to edge
            if (Double.IsInfinity(slope))
            {
                yInt       = 0;
                edgePoints = PlotUtilities.CalcUndefinedSlopeEdgePoints(scalingFactors, yInt);
            }
            else
            {
                yInt       = PlotUtilities.CalculateYIntercept(x1, y1, slope);
                edgePoints = PlotUtilities.CalcEdgePoints(scalingFactors, slope, yInt);
            }
            double length = PlotUtilities.CalculateLength(edgePoints);
            //Rotation angle (arcTan of height/width converted to degrees)
            double rotationAngle = (180 / Math.PI) * Math.Atan(slope);
            //Scale x and y appropriately
            double yScaleFactor = PlotUtilities.CalcYObjectScaleFactor(scalingFactors, rotationAngle);

            transformations.scale((length / 2), yScaleFactor);
            transformations.rotate(rotationAngle);
            Point midpoint = PlotUtilities.CalculateMidpoint(edgePoints[0], edgePoints[1]);

            //Translate to midpoint
            transformations.translate(midpoint.X, midpoint.Y);

            model.Material  = new DiffuseMaterial(Brushes.Green);
            model.Geometry  = StandardSquare.CreateSquare();
            model.Transform = transformations.getTransformations();
            return(model);
        }