matrix_rotate_arbitrary_axis 1.0.0+1

  • Readme
  • Changelog
  • Example
  • Installing
  • new49

matrix_rotate_arbitrary_axis #

Library to generate rotation matrix around arbitrary axis.

Original implementation of RotationMatrix class (matrix_rotate_arbitrary_axis.dart) by Glenn Murray.

Usage #

If you want to apply rotation matrix to canvas in Flutter you can just call:

// Build a rotation matrix for rotations about the line through (a, b, c) 
// parallel to [uUn, vUn, wUn] by the angle theta. 
final rotationMatrix = RotationMatrix(a, b, c, uUn, vUn, wUn, angleInRadians);
final matrix = rotationMatrix.getMatrix();
canvas.transform(matrix2);

The parameters are:

  • [a] x-coordinate of a point on the line of rotation.
  • [b] y-coordinate of a point on the line of rotation.
  • [c] z-coordinate of a point on the line of rotation.
  • [uUn] x-coordinate of the line's direction vector (unnormalized).
  • [vUn] y-coordinate of the line's direction vector (unnormalized).
  • [wUn] z-coordinate of the line's direction vector (unnormalized).
  • [theta] The angle of rotation, in radians.

Example #

See example in the example folder

example animation

[1.0.0+1] - Example added [May 2020] #

  • Added Flutter example app to show basic usage

[1.0.0] - Initial release [April 2020] #

  • Initial version ported from Java code

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:matrix_rotate_arbitrary_axis/matrix_rotate_arbitrary_axis.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Example App',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      debugShowCheckedModeBanner: false,
      home: MyHomePage(title: 'matrix_rotate_arbitrary_axis'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
  AnimationController animationController;

  @override
  void initState() {
    super.initState();
    animationController =
        AnimationController(vsync: this, duration: Duration(seconds: 4));
    animationController.forward();
    animationController.repeat(reverse: true);
  }

  @override
  void dispose() {
    super.dispose();
    animationController.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            AnimatedBuilder(
              animation: animationController,
              builder: (context, child) {
                final angleTween = Tween<double>(begin: 0.0, end: 3.14)
                    .animate(animationController);
                return Transform(
                  transform: RotationMatrix(0, 0, 0, 1, 1, 1, angleTween.value)
                      .getMatrix(),
                  child: Container(
                    color: Colors.blue,
                    width: 300,
                    height: 300,
                  ),
                );
              },
            ),
          ],
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  matrix_rotate_arbitrary_axis: ^1.0.0+1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:matrix_rotate_arbitrary_axis/matrix_rotate_arbitrary_axis.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
97
Overall:
Weighted score of the above. [more]
49
Learn more about scoring.

We analyzed this package on May 25, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.1
  • pana: 0.13.8-dev

Maintenance suggestions

The package description is too short. (-3 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
vector_math ^2.0.8 2.0.8
Dev dependencies
flutter_test