当前位置: 首页 > news >正文

长方形旋转计算最后的外层宽高,单元测试

思路:计算的变量
在这里插入图片描述
实际代码:

<template>
  <div>
    <div style="margin-bottom: 30px">
      rotate: {{rotate}}
      圆角:<input type="number" v-model="rotate" max="360" />
    </div>
    <div class="out-box">
      <div class="rect" :style="{width: width + 'px', height: height + 'px', transform: `rotate(${rotate}deg)`}"></div>
      <!-- <div class="abs" :style="{width: newWidth+'px', height: newHeight + 'px'}"></div> -->
      <!-- <div class="rect2" :style="{width: width+'px', height: height + 'px', transform: `rotate(${120}deg)`}"></div> -->
      <!-- <div class="abs2" style="width: 91.6025px; height: 58.6603px; transform: translateX(-41.8013px) translateY(19.6699px); borderColor: pink"></div> -->
      <div class="abs2" :style="{width: newWidth+'px', height: newHeight + 'px', transform: `translateX(-${endObj.x4}px) translateY(${endObj.y4}px)`}"></div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'HelloWorld',
  data() {
    return {
      width: 10,
      height: 100,
      rotate: 60,
      newWidth: '',
      newHeight: '',
      border: 1,
      endObj: {},
    };
  },
  mounted() {
    this.checkWH();
  },
  watch: {
    rotate() {
      this.checkWH();
    }
  },
  methods: {
    checkWH() {
      const rotate = this.rotate > 270 ?  360 - this.rotate : this.rotate > 180 ? this.rotate - 180 : this.rotate > 90 ? 90 - (this.rotate - 90) : this.rotate;
      const x1 = this.height * Math.sin(rotate * (Math.PI / 180));
      const y1 = Math.sqrt(this.height * this.height - x1 * x1);
      const minRotate = 180 - 90 - rotate; // 
      const x2 = this.width * Math.sin(minRotate * (Math.PI / 180));
      const y2 = Math.sqrt(this.width * this.width - x2 * x2);
      this.newWidth = Number(x1) + Number(x2);
      this.newHeight = Number(y1) + Number(y2);

      const x3 = this.newWidth / 2 - this.width / 2 - x2;
      const x4 = x2 + x3 + this.border;
      const y4 = (this.height - this.newHeight) / 2 - this.border;

      console.log('x1: ', x1);
      console.log('x2: ', x2);
      console.log('y1: ', y1);
      console.log('y2: ', y2);
      console.log('x3: ', x3);
      console.log('newWidth', this.newWidth);
      console.log('newHeight', this.newHeight);

      this.endObj = { x1, x2, y1, y2, x4, y4 };
    },
  },
};
</script>

<style scoped>
.rect {
  box-sizing: border-box;
  width: 10px;
  height: 100px;
  border: 1px solid red;
}
.out-box {
  box-sizing: border-box;
  border: 1px solid green;
  display: inline-block;
  position: relative;
}
.abs,
.abs2 {
  position: absolute;
  left: 0;
  top: 0;
  border: 1px solid orange;
}
.rect2 {
  position: absolute;
  border: 1px solid blue;
  top: 0;
  left: 0;
  box-sizing: border-box;
}

</style>

—end

相关文章:

  • HttpMediaTypeNotAcceptableException报错解决,状态码显示为406
  • 深度学习分类回归(衣帽数据集)
  • 98.在 Vue3 中使用 OpenLayers 根据 Resolution 的不同显示不同的地图
  • 【C++】数据类型
  • LLM中的transformer结构学习(二 完结 Multi-Head Attention、Encoder、Decoder)
  • Python之pyqt5生成计算机前端页面并运行
  • 零成本短视频爆款制造手册
  • Python正则表达式完全指南:从入门到精通
  • 使用AI一步一步实现若依前端(5)
  • Catia 转 StL:打通数字化设计与制造的关键纽带
  • TCP并发服务器
  • Vue 实现智能检测文字是否溢出,溢出显示省略号,鼠标悬浮显示全部【附封装组件完整代码+详细注释+粘贴即食】
  • Vue前端开发-Coupon组件
  • javaweb自用笔记:请求参数、响应、分层解耦、
  • 一二三应用开发平台——能力扩展:多数据源支持
  • 模板方法模式的C++实现示例
  • React基础之项目实战
  • 贵工程寝室报修系统的设计与实现
  • JavaScript 变量与常量全面解析
  • 在线程间共享数据_第三章_《C++并发编程》笔记
  • 全国首例闭环脊髓神经接口手术在浙江完成,截瘫患者实现自主行走
  • 特朗普与普京开始进行电话会谈,稍后还将致电泽连斯基
  • 43.2℃!河南林州打破全省5月最高温纪录,明后天高温将持续
  • 《缶翁的世界》首发:看吴昌硕王一亭等湖州籍书画家的影响
  • 西藏普兰县公安局网安大队向自媒体人宣传网络安全知识
  • 去年上海全市博物馆接待观众约4087万人次,同比增31.9%