Pasirinktinių Vienetų Keitiklis

Custom Units: Modeling, Formulas, and Best Practices

Define your own measurement units anchored to a 'Base Unit' or another custom unit. Model linear factors or full expressions, and organize consistent families for your project or domain.

Fundamental Concepts

What is a Custom Unit?
In this converter, a custom unit is user-defined and anchored to another custom unit (or to the Base Unit). You choose a name, symbol, reference, and a factor or expression that transforms values to the chosen reference.

Reference-Based Modeling

Your reference is another custom unit or 'Base Unit'.

The conversion expression maps input values into the reference unit's space (the system is intentionally unit-agnostic).

  • Dimension Safety
    By selecting a reference, you implicitly tie the custom unit to that family. Keep families consistent (e.g., related units referencing the same base).
  • Composability
    Change the reference later without renaming the unit—only the expression needs adjustment.
  • Auditability
    Every unit has a single, clear definition: reference + expression.

Factor vs Expression

Simple units use a constant factor (e.g., 1 foo = 0.3048 × Base).

Advanced units can use expressions with functions (e.g., 10 * log(x / 1e-3)).

  • Constant Factors
    Best for fixed linear relationships (length scales, area ratios, etc.).
  • Expressions
    Use math functions for derived or non-linear scales (ratios, logarithms, powers).
  • Constants
    Built-in constants like PI, E, PHI, SQRT2, SQRT3, LN2, LN10, LOG2E, LOG10E, AVOGADRO, PLANCK, LIGHT_SPEED, GRAVITY, BOLTZMANN.

Naming, Symbols, and Consistency

Choose short, unambiguous symbols. Avoid collisions with existing standards.

Document the intent in your organization—what it measures and why it exists.

  • Clarity
    Prefer concise symbols (1–4 chars recommended; UI allows up to 6).
  • Stability
    Treat symbols as stable identifiers across datasets and APIs.
  • Style
    Use SI-like casing where sensible (e.g., 'foo', 'kFoo', 'mFoo').
Key Takeaways
  • A custom unit = reference unit + conversion expression.
  • The reference anchors dimension; the expression defines value mapping.
  • Prefer constant factors for linear scales; use expressions for special cases.

Formula Language

Expressions support numbers, the variable x (input value), alias value, constants (PI, E, PHI, SQRT2, SQRT3, LN2, LN10, LOG2E, LOG10E, AVOGADRO, PLANCK, LIGHT_SPEED, GRAVITY, BOLTZMANN), arithmetic operators, and common math functions. Expressions evaluate to a value in the chosen reference unit.

Operators

OperatorMeaningExample
+Additionx + 2
-Subtraction/Unary Negationx - 5, -x
*Multiplication2 * x
/Divisionx / 3
**Power (use **; ^ is auto-converted)x ** 2
()Precedence(x + 1) * 2

Functions

FunctionSignatureExample
sqrtsqrt(x)sqrt(x^2 + 1)
cbrtcbrt(x)cbrt(x)
powpow(a, b)pow(0.3048, 2)
absabs(x)abs(x)
minmin(a, b)min(x, 100)
maxmax(a, b)max(x, 0)
roundround(x)round(x * 1000) / 1000
trunctrunc(x)trunc(x)
floorfloor(x)floor(x)
ceilceil(x)ceil(x)
sinsin(x)sin(PI/6)
coscos(x)cos(PI/3)
tantan(x)tan(PI/8)
asinasin(x)asin(0.5)
acosacos(x)acos(0.5)
atanatan(x)atan(1)
atan2atan2(y, x)atan2(1, x)
sinhsinh(x)sinh(1)
coshcosh(x)cosh(1)
tanhtanh(x)tanh(1)
lnln(x)ln(x)
loglog(x)log(100)
log2log2(x)log2(8)
expexp(x)exp(1)
degreesdegrees(x)degrees(PI/2)
radiansradians(x)radians(180)
percentpercent(value, total)percent(25, 100)
factorialfactorial(n)factorial(5)
gcdgcd(a, b)gcd(12, 8)
lcmlcm(a, b)lcm(12, 8)
clampclamp(value, min, max)clamp(x, 0, 100)
signsign(x)sign(-5)
nthRootnthRoot(value, n)nthRoot(8, 3)

Expression Rules

  • x is the input value; alias value is also available.
  • Use explicit multiplication (e.g., 2 * PI, not 2PI).
  • Constants available: PI, E, PHI, SQRT2, SQRT3, LN2, LN10, LOG2E, LOG10E, AVOGADRO, PLANCK, LIGHT_SPEED, GRAVITY, BOLTZMANN.
  • Angles for trigonometric functions are radians (use degrees() and radians() helper functions for conversion).
  • Reference other custom units by name (snake_case) or symbol; their current toBase is injected as constants.
  • Use ** for powers (the engine auto-converts ^ to **).
  • Smart input normalization: ×, ÷, π, ², ³ are automatically converted to *, /, PI, ^2, ^3.
  • Helper functions available: degrees(), radians(), percent(), factorial(), gcd(), lcm(), clamp(), sign(), nthRoot().
  • Enhanced error detection prevents common mistakes (log of negative numbers, sqrt of negative numbers, division by zero).
  • Custom unit referencing: Use other units as variables in expressions (e.g., 'x * A' where A is another custom unit).
  • Whitespace is ignored; use parentheses to control precedence.
  • Expressions must produce a finite numeric result for valid inputs.
Formula Essentials
  • Use explicit multiplication (e.g., 2 * PI).
  • Angles for trig functions are radians.
  • log(x) is base 10; ln(x) is natural log (base e).

Dimensional Analysis & Strategies

This custom system is unit-agnostic. Model families by anchoring related units to the same 'Base Unit' (or a shared reference). Keep meaning consistent across the family you design.

Modeling Strategies

StrategyWhen to UseNotes
Direct FactorLinear relationships (e.g., 1 foo = k × Base).Use a constant number (no x). Stable and precise.
Power ScalingDerived from a base scale (k^2, k^3).Use pow(k, n) where k is the base scale.
Ratio or NormalizationUnits defined relative to a reference level (e.g., x / ref).Useful for index-like measures; keep ref explicit in the expression.
Logarithmic ScalePerceptual or power-ratio scales (e.g., dB-style 10 * log(x/ref)).Ensure domain is positive; document reference value.
Affine MappingRare cases with offsets (a * x + b).Offsets change zero points—apply only when conceptually justified.

Editor & Validation

Create units with a name, symbol (up to 6 chars), color tag, a reference (Base Unit or another custom unit), and a factor/expression. The editor validates formulas in real time with enhanced error detection and prevents circular references.

  • Reference options include 'Base Unit' and existing custom units. Unsafe options that would create cycles are filtered out automatically.
  • Variables: use x (or value) for the input value. Reference other custom units by snake_case name or by symbol; their current toBase values are injected as constants.
  • Supported constants: PI, E, PHI, SQRT2, SQRT3, LN2, LN10, LOG2E, LOG10E, AVOGADRO, PLANCK, LIGHT_SPEED, GRAVITY, BOLTZMANN.
  • Core functions: sqrt, cbrt, pow, abs, min, max, round, trunc, floor, ceil, sin, cos, tan, asin, acos, atan, atan2, sinh, cosh, tanh, ln, log, log2, exp.
  • Helper functions: degrees(), radians(), percent(), factorial(), gcd(), lcm(), clamp(), sign(), nthRoot() for enhanced UX.
  • Operators: +, -, *, /, ** for power. Smart input normalization: ×, ÷, π, ², ³ are automatically converted.
  • Real-time validation with preview (e.g., 10 x → result), complexity classification (simple/moderate/complex), and context-aware suggestions.
  • Enhanced error detection catches common mistakes: logarithms of non-positive numbers, square roots of negative numbers, division by zero.
  • Advanced cycle detection prevents units from depending on themselves (directly or indirectly) with clear error messages.
  • Interactive help panel with categorized examples, clickable formula snippets, and custom unit buttons for easy insertion.

Best Practices

  • Prefer a constant factor if possible; expressions only when necessary.
  • Choose a reference unit that is stable, widely understood, and unlikely to change.
  • Avoid circular chains of references; keep graphs acyclic.
  • Add sample values and cross-check with independent calculators or known identities.
  • Keep symbols short, unique, and documented for your organization.
  • If using logs, record the reference value, base, and intended domain of x.
Quality Checklist
  • Test with 3–5 representative values and verify round-trip conversions.
  • Avoid circular references; pick a stable reference unit.
  • Document assumptions (domains, offsets, typical ranges).

Starter Templates & Examples

These examples illustrate common modeling patterns in this custom-only system. Replace constants and references with your needs.

NameFormulaReferenceNotes
Base-Scaled Unit (foo)0.3048Base UnitDefines 1 foo = 0.3048 × Base (simple linear factor).
Power-Scaled (foo²)pow(0.3048, 2)Base UnitDerived from a base scale (k^2).
Volume-Scaled (foo³)pow(0.3048, 3)Base UnitDerived from a base scale (k^3).
Index from Referencex / 42Base UnitNormalize by a fixed level (domain x > 0).
Power Ratio (dB-style)10 * log(x / 0.001)Base UnitLogarithmic measure relative to 1 mW (example). Ensure x > 0.
Geometric Factor2 * PI * 0.5Base UnitExample of constants and multiplication.
Reference Other Custom UnitA * 2Custom Unit AUse another unit's symbol/name as a constant in expressions.
Complex Unit Relationshipsqrt(x^2 + base_length^2)Base UnitPythagorean relationship using custom unit 'base_length' as a constant.
Scaled Unit with Offsetx * scale_factor + offset_unitBase UnitLinear transformation using two other custom units as constants.
Percentage of Reference Unitpercent(x, reference_value)Base UnitExpress input as percentage of another custom unit using helper function.
Clamped Unit Rangeclamp(x * multiplier, min_unit, max_unit)Base UnitConstrain values between two custom unit constants using clamp helper.
Unit Ratio with GCDx / gcd(x, common_divisor)Base UnitMathematical relationship using GCD helper with custom unit constant.
Angular Conversion Chaindegrees(x * PI / reference_angle)Custom Angular UnitConvert to degrees using custom angle unit and degrees() helper function.

Governance & Collaboration

  • Maintain a catalog of approved custom units with owners and review dates.
  • Use versioning when definitions evolve; avoid breaking changes to symbols.
  • Record provenance for constants and references (standards, literature, internal docs).
  • Automate validation tests (range checks, sample conversions, monotonicity).

FAQ

Should I use a constant factor or an expression?

Prefer a constant factor whenever the relationship is linear and fixed. Use expressions only when the mapping depends on x or requires functions (powers, logs, trig).

How do I pick a reference unit?

Choose a stable, widely understood unit that captures the dimension you intend (e.g., meter for length, m² for area). The reference anchors dimensional meaning.

Are angles in degrees or radians?

Radians. Convert degrees by multiplying by PI/180 before using trig functions.

Can I chain custom units?

Yes, but avoid cycles. Keep the graph acyclic and document the chain to preserve clarity.

Visas Įrankių Katalogas

Visi 71 įrankiai, pasiekiami UNITS

Filtruoti pagal:
Kategorijos:

Papildomai