सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
vector_math पैकेज 2D और 3D वेक्टर, मैट्रिक्स, और क्वाटर्नियन ऑपरेशन का एक व्यापक सेट प्रदान करता है, जो ग्राफिक्स, एनिमेशन, और गेम डेवलपमेंट के लिए अनुकूलित है। गूगल द्वारा बनाया गया, यह उच्च प्रदर्शन गणितीय उपकरण प्रदान करता है जो फ्लटर एप्लिकेशन के लिए विभिन्न प्लेटफॉर्मों पर अनुकूलित है। यह लाइब्रेरी डॉट उत्पाद, क्रॉस उत्पाद, परिवर्तन, और घूर्णन जैसी मूल ज्यामितीय गणनाओं का समर्थन करती है, जिससे यह स्थानिक डेटा को कुशलता से संभालने के लिए आदर्श है। यह हल्का, अच्छी तरह से दस्तावेज़ित है, और फ्लटर के रेंडरिंग पाइपलाइन के साथ बिना किसी दिक्कत के एकीकृत किया जा सकता है।
उपयोग
2D/3D ग्राफिक्स रेंडरिंग
गेम डेवलपमेंट
एनिमेशन प्रणाली
स्थानिक परिवर्तन
फिजिक्स सिमुलेशन
कैमरा और वस्तु स्थिति
मुख्य विशेषताएँ
2D और 3D सदिश और मैट्रिक्स के लिए समर्थन
3D घूर्णन के लिए चतुर्भुज समर्थन
उच्च प्रदर्शन गणितीय संक्रियाएँ
क्रॉस-प्लेटफॉर्म संगतता
स्पष्ट और सुव्यवस्थित API डिज़ाइन
निर्मित रूपांतरण उपकरण
इनके लिए उपयुक्त
गेम्स पर काम कर रहे Flutter विकासकर्ता
सटीक स्थिति की आवश्यकता वाले UI एनीमेशन
आवधिक वास्तविकता एप्लिकेशन
ग्राफिक्स-भारी एप्लिकेशन
गणित-सामग्री वाला ऐप तर्क
विचार योग्य बातें
सामान्य उद्देश्य के लिए गणित के लिए नहीं बनाया गया है
रैखिक बीजगणित की समझ की आवश्यकता है
ज्यामितीय संचालनों तक सीमित
कोई निर्मित अनुक्रमण नहीं है
अन्य गणित या ग्राफिक्स पैकेज के साथ उपयोग करने में सबसे अच्छा
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
Introduction
A Vector math library for 2D and 3D applications.
Features
2D, 3D, and 4D vector and matrix types.
Quaternion type for animating rotations.
Collision detection: AABB, rays, spheres, ...
Utilities like color and common rendering related operations
Flexible getters and setters, for example, position.xwz = color.grb;.
import'package:vector_math/vector_math.dart';
voidmain() {
Vector3 x = Vector3.zero(); // Zero vectorVector4 y = Vector4.all(4.0); // Vector with 4.0 in all lanes
x.zyx = y.xzz; // Sets z,y,x the values in x,z,z
}
2. Transforming a vector.
import'dart:math';
import'package:vector_math/vector_math.dart';
voidmain() {
// Rotation of PI/2 degrees around the Y axis followed by a// translation of (5.0, 2.0, 3.0).Matrix4 T = Matrix4.rotationY(PI * 0.5)..translate(5.0, 2.0, 3.0);
// A point.Vector3 position = Vector3(1.0, 1.0, 1.0);
// Transform position by T.
T.transform3(position);
}
3. Invert a matrix
import'dart:math';
import'package:vector_math/vector_math.dart';
voidmain() {
// Rotation of 90 degrees around the Y axis followed by a// translation of (5.0, 2.0, 3.0).Matrix4 T = Matrix4.rotationY(PI * 0.5)..translate(5.0, 2.0, 3.0);
// Invert T.
T.invert();
// Invert just the rotation in T.
T.invertRotation();
}
4. Rotate a vector using a quaternion
import'dart:math';
import'package:vector_math/vector_math.dart';
voidmain() {
// The X axis.Vector3 axis = Vector3(1.0, 0.0, 0.0);
// 90 degrees.double angle = PI / 2.0;
// Quaternion encoding a 90 degree rotation along the X axis.Quaternion q = Quaternion.axisAngle(axis, angle);
// A point.Vector3 point = Vector3(1.0, 1.0, 1.0);
// Rotate point by q.
q.rotate(point);
}
5. Check if two axis aligned bounding boxes intersect
import'package:vector_math/vector_math.dart';
voidmain() {
// Define the first box with a minimum and a maximum.Aabb2 aabbOne = Aabb2.minMax(Vector2.zero(), Vector2(4.0, 4.0));
// Define the second boxAabb2 aabbTwo = Aabb2.minMax(Vector2(5.0, 5.0), Vector2(6.0, 6.0));
// Extend the second box to contain a point
aabbTwo.hullPoint(Vector2(3.0, 3.0));
// Check if the two boxes intersect, returns true in this case.bool intersect = aabbOne.intersectsWithAabb2(aabbTwo);
}
6. Check where a ray and a sphere intersect
import'package:vector_math/vector_math.dart';
voidmain() {
// Define a ray starting at the origin and going into positive x-direction.Ray ray = Ray.originDirection(Vector3.zero(), Vector3(1.0, 0.0, 0.0));
// Defines a sphere with the center (5.0 0.0 0.0) and a radius of 2.Sphere sphere = Sphere.centerRadius(Vector3(5.0, 0.0, 0.0), 2.0);
// Checks if the ray intersect with the sphere and returns the distance of the// intersection from the origin of the ray. Would return null if no intersection// is found.double distanceFromOrigin = ray.intersectsWithSphere(sphere);
// Evaluate the position of the intersection, in this case (3.0 0.0 0.0).Vector3 position = ray.at(distanceFromOrigin);
}
7. Work with colors
import'package:vector_math/vector_math.dart';
voidmain() {
// Access a build-in color, colors are stored in 4-dimensional vectors.Vector4 red = Colors.red;
Vector4 gray = Vector4.zero();
// Convert the red color to a grayscaled color.Colors.toGrayscale(red, gray);
// Parse a blue color from a hex string.Vector4 blue = Vector4.zero();
Colors.fromHexString('#0000FF', blue);
// Convert the blue color from RGB to HSL.Colors.rgbToHsl(blue, blue);
// Reduce the lightness of the color by 50%.
blue.z *= 0.5;
// Convert the HSL color back to RGB.Colors.hslToRgb(blue, blue);
}
8. Use 64bit float precision (instead of 32bit)
// Use different import statement.// Which is a drop-in replacement for 'package:vector_math/vector_math.dart'import'package:vector_math/vector_math_64.dart';
voidmain() {
// Types work the same, but using 64 bit storage.Vector3 x = Vector3.zero();
Matrix4 m = Matrix4.identity();
}
Development
To run the unit tests:
~/src/vector_math/> dart test
To automatically generate the latest version of vector_math_64: