zodiak1

useModeling

Dec 16th, 2022
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { useEffect } from 'react'
  2. import { useSelector } from 'react-redux'
  3. import {
  4.   selectIsModeling,
  5.   selectObjectModelm,
  6.   selectObjectModelR,
  7. } from 'selectors'
  8.  
  9. export const useModeling = () => {
  10.   const isModeling = useSelector(selectIsModeling)
  11.  
  12.   const m = useSelector(selectObjectModelm)
  13.   const r = useSelector(selectObjectModelR)
  14.  
  15.   const g = 9.8
  16.   const V0 = 0
  17.   const t = 0.1
  18.  
  19.   const n = 0.0182
  20.   const C = 0.4
  21.   const S = Math.PI * r * r
  22.   const p = 1.89
  23.  
  24.   const k1 = 6 * Math.PI * r * n
  25.   const k2 = (C * S * p) / 2
  26.  
  27.   useEffect(() => {
  28.     console.log('modeling')
  29.     if (!isModeling) return
  30.  
  31.     let i = 100
  32.     let Vi = V0
  33.  
  34.     const calculateVi = function () {
  35.       console.log(123)
  36.       if (!isModeling || --i === 0) return
  37.  
  38.       const CC = (m * g - k1 * Vi - k2 * Vi * Vi) / m
  39.       const DD = Vi + t * CC
  40.       const c = (m * g - k1 * CC - k2 * DD * DD) / m
  41.  
  42.       console.log(Vi)
  43.       Vi = Vi + (t / 2) * (CC + c)
  44.  
  45.       calculateVi()
  46.     }
  47.  
  48.     calculateVi()
  49.   }, [isModeling])
  50. }
  51.  
Add Comment
Please, Sign In to add comment