
<template>
<svg width="400" height="400" class="BG" @mousemove="mousemove">
<path class="Line"
:d="`M${StartPoint[0]} ${StartPoint[1]} S${ControlPoint[0]} ${ControlPoint[1]} ${EndPoint[0]} ${EndPoint[1]}`" />
<circle :cx="StartPoint[0]" :cy="StartPoint[1]" r="5" style="fill:pink; stroke:red; stroke-width:2;" />
<circle :cx="EndPoint[0]" :cy="EndPoint[1]" r="5" style="fill:pink; stroke:red; stroke-width:2;" />
<circle :cx="ControlPoint[0]" :cy="ControlPoint[1]" r="5" style="fill:pink; stroke:red; stroke-width:2;" />
svg>
template>
<script setup>
import { nextTick, ref } from 'vue';
const StartPoint = ref([200, 200]);
const EndPoint = ref([400, 200])
const ControlPoint = ref([300, 200])
const ConstantAngle = 45;
const ControlPointCompute = () => {
const radian = Math.atan2((EndPoint.value[1] - StartPoint.value[1]), (EndPoint.value[0] - StartPoint.value[0]));
const CosRadian = Math.cos(radian);
const Angle = radian * (180 / Math.PI);
const ControlAngle = Angle - (CosRadian * ConstantAngle);
const distance = Math.sqrt(Math.pow(Math.abs(EndPoint.value[0] - StartPoint.value[0]), 2) + Math.pow(Math.abs(EndPoint.value[1] - StartPoint.value[1]), 2));
const distanceByCosRadian = distance / (2 - Math.abs(CosRadian) * (1 - 0.414));
const X = Math.cos(((2 * Math.PI) / 360) * ControlAngle) * distanceByCosRadian;
const Y = Math.sin(((2 * Math.PI) / 360) * ControlAngle) * distanceByCosRadian;
ControlPoint.value = [X + 200, Y + 200];
}
const R2A = 180 / Math.PI;
const A2R = (2 * Math.PI) / 360
const TestCompute = (X, Y) => {
const DX = Y[0] - X[0];
const DY = Y[1] - X[1];
const radian = Math.atan2(DY, DX);
const CosRadian = Math.cos(radian);
const dis = Math.sqrt(Math.pow(Math.abs(DX), 2) + Math.pow(Math.abs(DY), 2)) / (2 - Math.abs(CosRadian) * (1 - 0.414));
const ControlRadian = A2R * (radian * R2A - (CosRadian * ConstantAngle));
ControlPoint.value = [Math.cos(ControlRadian) * dis + X[0], Math.sin(ControlRadian) * dis + X[1]];
}
TestCompute(StartPoint.value, EndPoint.value);
const mousemove = (e) => {
const { offsetX, offsetY } = e;
EndPoint.value[0] = offsetX;
EndPoint.value[1] = offsetY;
TestCompute(StartPoint.value, EndPoint.value);
}
script>
<style lang="less" scoped>
.BG {
background-color: rgba(255, 255, 255, 0.1);
}
.Line {
fill: none;
stroke: red;
stroke-width: 2;
}
style>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98