Last active
          February 2, 2017 19:59 
        
      - 
      
- 
        Save scottrippey/c0fca35232a361308a44d25c5e975758 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function calculatePerpendicularIntersect(centerPosition, startPosition, endPosition) { | |
| const { x: cX, y: cY } = centerPosition; | |
| const { x: sX, y: sY } = startPosition; | |
| const { x: eX, y: eY } = endPosition; | |
| const slopeStart = (cX - sX) / (cY - sY); | |
| const slopePerp = 1 / slopeStart; | |
| const intersectX = (slopeStart * sX - slopePerp * eX + eY - sY) / (slopeStart - slopePerp); | |
| const intersectY = (intersectX - sX) * slopeStart + sY; | |
| return { | |
| x: intersectX, | |
| y: intersectY | |
| }; | |
| } | |
| function calculateControlPoint(centerPosition, startPosition, endPosition, perc) { | |
| const perpIntersect = calculatePerpendicularIntersect(centerPosition, startPosition, endPosition); | |
| return { | |
| x: startPosition.x + (perpIntersect.x - startPosition.x) * perc, | |
| y: startPosition.y + (perpIntersect.y - startPosition.y) * perc | |
| } | |
| } | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment