櫻之舞

文章 评论 浏览 28

櫻之舞 2025-02-21 02:18:21

您为什么假设“访问者”的意思是“获取”?访问者只是一个通用术语,可提供某种访问该属性的访问。可以读取访问
(“ getter”),写入访问(“ setter”)或其他东西。事件也有登录器(添加和删除,尽管还有更多)。

配件比“与成员互动的方法”短,而不是“ Geters and Setters”。也许“ Geters and Setters”是您在这里寻找的东西。

最终,出于原因:这个概念需要一个名称来简化和形式化用法,这就是选择的单词。

Why are you assuming that "accessor" means "get"? Accessor is just a generic term that provides some kind of access to the property. That could be read access
("getter"), write access ("setter"), or something else. Events also have accessors (add and remove, although more are possible).

Accessors is simply shorter than "methods for interacting with the member", and more generic than "getters and setters". Maybe "getters and setters" is the thing you're looking for here.

Ultimately, though, for reasons: the concept needed a name to simplify and formalize usage, and that was the word that was chosen.

c#为什么属性的获取和设置方法都称为访问者,但不称为登录器和突变器?

櫻之舞 2025-02-20 23:33:02

disableAutoFocus = {true}属性添加到任何popover或依靠popover的任何其他组件都应防止任何滚动怪异。您可能还需要使用disableenforcefocus,具体取决于您想要的行为。这些是来自modal组件的道具(其中popover是): https://mui.com/material-ui/api/modal/

我只是跑了在iframe中使用&lt;菜单 /&gt; < /code>时,将其纳入类似的问题,该< /&gt; < /code>在打开时会导致浏览器滚动页面并专注于iframe。在此&lt;菜单/&gt;的情况下,我还必须将autofocusItem添加到menulistprops,所以这些是我的相关道具:

<Menu
  MenuListProps={{
    autoFocusItem: false,
  }}
  disableAutoFocus
  /* other props */
>
  {/* MenuList components */}
</Menu>

Adding the disableAutoFocus={true} property to any Popover or any other component relying on Popover should prevent any scrolling weirdness. You might need to use disableEnforceFocus as well, depending on what behavior you desire. These are props from the Modal component (of which Popover is a "child" of): https://mui.com/material-ui/api/modal/

I just ran into a similar problem when using a <Menu /> in an iframe, which when opened, caused the browser to scroll the page and focus on the iframe. In the case of this <Menu />, I also had to add a autoFocusItem: false property to the MenuListProps, so these are the relevant props for me:

<Menu
  MenuListProps={{
    autoFocusItem: false,
  }}
  disableAutoFocus
  /* other props */
>
  {/* MenuList components */}
</Menu>

如何防止材料-UI弹出式滚动在打开时滚动iframe?

櫻之舞 2025-02-20 16:44:03

最简单的解决方案是创建JavaScript函数,并为AJAX Success回调称其为调用。

function callServerAsync(){
    $.ajax({
        url: '...',
        success: function(response) {

            successCallback(response);
        }
    });
}

function successCallback(responseObj){
    // Do something like read the response and show data
    alert(JSON.stringify(responseObj)); // Only applicable to a JSON response
}

function foo(callback) {

    $.ajax({
        url: '...',
        success: function(response) {
           return callback(null, response);
        }
    });
}

var result = foo(function(err, result){
          if (!err)
           console.log(result);
});

The simplest solution is to create a JavaScript function and call it for the Ajax success callback.

function callServerAsync(){
    $.ajax({
        url: '...',
        success: function(response) {

            successCallback(response);
        }
    });
}

function successCallback(responseObj){
    // Do something like read the response and show data
    alert(JSON.stringify(responseObj)); // Only applicable to a JSON response
}

function foo(callback) {

    $.ajax({
        url: '...',
        success: function(response) {
           return callback(null, response);
        }
    });
}

var result = foo(function(err, result){
          if (!err)
           console.log(result);
});

如何从异步电话中返回响应?

櫻之舞 2025-02-20 16:28:49

问题是row ['startts']&lt; data ['startts']&lt;行['endts'],您可以使用

data['startTS'].between(row['startTS'], row['endTS'], inclusive='neither')
# or
(row['startTS'] < data['startTS']) & (df['startTS'] < row['endTS'])

Problem is row['startTS'] < data['startTS'] < row['endTS'], you can use

data['startTS'].between(row['startTS'], row['endTS'], inclusive='neither')
# or
(row['startTS'] < data['startTS']) & (df['startTS'] < row['endTS'])

Python:如何使用系列中的值过滤Pandas DataFrame?

櫻之舞 2025-02-20 11:10:28

使用您的下载文件,并将我的区域设置设置为德语(德国),我可以复制您的问题。

您需要告诉电源查询(这就是您使用data =&gt;从text/csv操作中使用时使用的内容)源文件正在使用中心值。

为此:

  • 当窗口打开时,而不是 load 选择变换数据
  • 当PQ编辑器打开时,选择home =&gt;高级编辑器
  • 更改第二行以读取:
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, 
    {"Column2", type number}, {"Column3", type number}},"en-US")
  • 请注意,我们已经更改了数据类型并在末尾添加了文化参数
    • 这可以从UI完成。我会让你探索。

我的高级编辑器中的整个代码(由于语言而可能有所不同):

let
    Source = Csv.Document(File.Contents("C:\Users\ron\Desktop\Invariants_at_QPs.txt"),[Delimiter=",", Columns=3, Encoding=1252, QuoteStyle=QuoteStyle.None]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, 
    {"Column2", type number}, {"Column3", type number}},"en-US")
in
    #"Changed Type"

结果的一部分:

”输入图像描述在这里”

With your downloaded file, and setting my Regional settings to German(Germany), I can reproduce your problem.

You will need to tell Power Query (that's what you are using when you do the Data=>from text/csv operation) that the source file is using US-centric values.

To do this:

  • When the window opens, instead of Load select Transform Data.
  • When the PQ Editor opens, select Home=>Advanced Editor
  • Change the second line to read:
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, 
    {"Column2", type number}, {"Column3", type number}},"en-US")
  • Note that we have changed both the data type and added the culture argument at the end
    • This could be done from the UI. I will leave you to explore that.

The entire code in my Advanced Editor (might be different in yours due to language):

let
    Source = Csv.Document(File.Contents("C:\Users\ron\Desktop\Invariants_at_QPs.txt"),[Delimiter=",", Columns=3, Encoding=1252, QuoteStyle=QuoteStyle.None]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, 
    {"Column2", type number}, {"Column3", type number}},"en-US")
in
    #"Changed Type"

And a screeshot of part of the results:

enter image description here

Excel导入TXT文件 - 未识别的十进制符号

櫻之舞 2025-02-20 07:44:21

我弄清楚了这个问题,正是相机出于神秘的原因在特定时间之前返回框架。

1-我尝试了没有套接字和线程的代码,以避免复杂性,因此主要问题是来自相机

2-启动应用程序之间的差异很小(thing time.time.time()),所以我现在发送从请求中,从主要应用程序到其他服务器的时间戳,因此该过程的序列现在看起来不错。

I figure out the issue, it was the camera that return the frame before the specific time for a mysterious reason.

1- I tried the code without socket and threads, to avoid complexity so the main problem was from the camera

2- there is a slight difference between the applications when they start up(take time.time()) so now I'm sending the timestamp from the main application to other servers in the request, so the sequences for the process seem good now.

通过Threading.Timer(700ms)将数据发送到服务器后,我在另一侧685ms收到?

櫻之舞 2025-02-20 07:06:35

也许这取决于.env文件的路径,也取决于您执行脚本的方式。也许要运行的firebase命令(例如firebase servions - 仅函数)在路径透视图中运行node Index.js功能)。

换句话说,您需要确定主脚本的路径,然后确定.env文件的相对路径,并将此路径设置为dotenv.config()。

Maybe it depends on the path of .env file and also, the way you are executing the script. Maybe the firebase commands to run (e.g., firebase serve --only functions) is different of to run node index.js in the path perspective (if you are using a cloud function).

In other words, you need to determine path of your main script and, then, determine the relative path of your .env file to this and set this path to dotenv.config().

&quot“ dotenv.load()不是函数”在尝试运行节点脚本的同时

櫻之舞 2025-02-20 03:18:12

您在另一个按钮内放一个按钮。从块按钮内的跨度中删除BTN BTN-primary

function toDefault() {
    const btn = document.getElementById('submitBtn');
    btn.innerHTML = '<span>Submit</span>';
}

You put a button inside another button. Remove btn btn-primary from the span inside the block button.

function toDefault() {
    const btn = document.getElementById('submitBtn');
    btn.innerHTML = '<span>Submit</span>';
}

当我切换到旋转器时,为什么Bootstrap调整按钮大小?

櫻之舞 2025-02-20 01:30:43

实际上,所需的一切都是将线性scaleeffect替换为自定义几何效果,该效应提供了必要的比例曲线(最初生长然后跌落)。

这是一种可能的方法的演示(用Xcode 13.4/ios 15.5)

“

主要部分:

struct JumpyEffect: GeometryEffect {
    let offset: Double
    var value: Double

    var animatableData: Double {
        get { value }
        set { value = newValue }
    }

    func effectValue(size: CGSize) -> ProjectionTransform {
        let trans = (value + offset * (pow(5, value - 1/pow(value, 5))))
        let transform = CGAffineTransform(translationX: size.width * 0.5, y: size.height * 0.5)
            .scaledBy(x: trans, y: trans)
            .translatedBy(x: -size.width * 0.5, y: -size.height * 0.5)
        return ProjectionTransform(transform)
    }
}

用法

.modifier(JumpyEffect(offset: isPressed ? 0.3 : 0, value: isPressed ? 0.8 : 1))

Actually all is needed is to replace linear scaleEffect with custom geometry effect that gives needed scale curve (initially growing then falling).

Here is a demo of possible approach (tested with Xcode 13.4 / iOS 15.5)

demo

Main part:

struct JumpyEffect: GeometryEffect {
    let offset: Double
    var value: Double

    var animatableData: Double {
        get { value }
        set { value = newValue }
    }

    func effectValue(size: CGSize) -> ProjectionTransform {
        let trans = (value + offset * (pow(5, value - 1/pow(value, 5))))
        let transform = CGAffineTransform(translationX: size.width * 0.5, y: size.height * 0.5)
            .scaledBy(x: trans, y: trans)
            .translatedBy(x: -size.width * 0.5, y: -size.height * 0.5)
        return ProjectionTransform(transform)
    }
}

and usage

.modifier(JumpyEffect(offset: isPressed ? 0.3 : 0, value: isPressed ? 0.8 : 1))

Complete code on GitHub

Swiftui动画:向上/向上推动按下,发行弹簧 - 如何进行“移动”部分

櫻之舞 2025-02-19 10:51:10

sapply在其余列上循环。

sapply(c('Method2', 'Method3', 'Method4'), \(x) 
       cor.test(database[, 1], database[, x], method='spearman')[c('estimate', 'p.value')])
#          Method2     Method3      Method4    
# estimate 0.8787879   0.9272727    0.9030303  
# p.value  0.001977059 0.0001301624 0.000880225

In an sapply loop over the remaining columns .

sapply(c('Method2', 'Method3', 'Method4'), \(x) 
       cor.test(database[, 1], database[, x], method='spearman')[c('estimate', 'p.value')])
#          Method2     Method3      Method4    
# estimate 0.8787879   0.9272727    0.9030303  
# p.value  0.001977059 0.0001301624 0.000880225

使用Spearman Rho系数比较排名

櫻之舞 2025-02-19 05:26:25

问题的逻辑说明是,当您启动程序时,OS中的当前工作目录不是包含您的node.html文件的目录。因此,fs.ReadFileSync('node.html',“ utf8”);仅在当前工作目录中查看的目录找不到目标文件。

正如您发现的那样,您可以通过构建一个更完整的路径来解决问题,该路径指定所需的实际目录,而不仅仅是普通文件名。您还可以在启动应用程序之前确保将当前的工作目录正确设置为服务器目录。

构建自己通往服务器目录的路径的通常方法是使用path.join()

fs.readFileSync(path.join(__dirname, 'node.html'), "utf8");

The logical explanation for your issue is that when you start your program the current working directory in the OS is not the directory that contains your node.html file. Thus, fs.readFileSync('node.html', "utf8"); which only looks in the current working directory does not find the target file.

As you discovered, you can fix the problem by building a more complete path that specifies that actual directory you want, not just the plain filename. You could also make sure that the current working directory was set properly to your server directory before you started your app.

The usual way to build your own path to your server directory is by using path.join():

fs.readFileSync(path.join(__dirname, 'node.html'), "utf8");

fs.ReadFileSync不识别文件

櫻之舞 2025-02-18 22:17:49

我将考虑与先前答案使用mask径向梯度。只需调整两个变量,直到获得所需的结果:

.box {
  height:300px;
  background: url(https://images.unsplash.com/photo-1581362508717-f542c1ecf295?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1651&q=80) center/cover;
  -webkit-mask:
    radial-gradient(var(--r1,100%) var(--r2,50%) at top   ,white 79.5%,transparent 80%) top left,
    radial-gradient(var(--r1,100%) var(--r2,50%) at bottom,transparent 79.5%,white 80%) top center,
    radial-gradient(var(--r1,100%) var(--r2,50%) at top   ,white 79.5%,transparent 80%) top right;
  mask:
    radial-gradient(var(--r1,100%) var(--r2,50%) at top   ,white 79.5%,transparent 80%) top left,
    radial-gradient(var(--r1,100%) var(--r2,50%) at bottom,transparent 79.5%,white 80%) top center,
    radial-gradient(var(--r1,100%) var(--r2,50%) at top   ,white 79.5%,transparent 80%) top right;
   /* adjust the 150% to control the covered area, the bigger the value the bigger the area will be*/
  -webkit-mask-size:33.4% 150%;
  -webkit-mask-repeat:no-repeat;
  mask-size:33.4% 150%;
  mask-repeat:no-repeat;
}
<div class="box" style="--r1:130%;--r2:71.5%">

</div>

要理解技巧bask background

.box {
  height:300px;
  background:
    radial-gradient(var(--r1,100%) var(--r2,50%) at top   ,red 79.5%,transparent 80%)  top left,
    radial-gradient(var(--r1,100%) var(--r2,50%) at bottom,transparent 79.5%,blue 80%) top center,
    radial-gradient(var(--r1,100%) var(--r2,50%) at top   ,red 79.5%,transparent 80%)  top right;
  mask:
    radial-gradient(var(--r1,100%) var(--r2,50%) at top   ,red 79.5%,transparent 80%)  top left,
    radial-gradient(var(--r1,100%) var(--r2,50%) at bottom,transparent 79.5%,blue 80%) top center,
    radial-gradient(var(--r1,100%) var(--r2,50%) at top   ,red 79.5%,transparent 80%)  top right;
  background-size:33.4% 150%;
  background-repeat:no-repeat;
  border:1px solid;
}
<div class="box" style="--r1:130%;--r2:71.5%">

</div>


将其应用于您的代码:

.hero-container {
  background: url(https://images.unsplash.com/photo-1581362508717-f542c1ecf295?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1651&q=80) top/cover;
  padding: 16.625rem 0;
  -webkit-mask:
    radial-gradient(var(--r1,160%) var(--r2,68.15%) at top   ,white 79.5%,transparent 80%) top left,
    radial-gradient(var(--r1,160%) var(--r2,68.15%) at bottom,transparent 79.5%,white 80%) top center,
    radial-gradient(var(--r1,160%) var(--r2,68.15%) at top   ,white 79.5%,transparent 80%) top right;
  mask:
    radial-gradient(var(--r1,160%) var(--r2,68.15%) at top   ,white 79.5%,transparent 80%) top left,
    radial-gradient(var(--r1,160%) var(--r2,68.15%) at bottom,transparent 79.5%,white 80%) top center,
    radial-gradient(var(--r1,160%) var(--r2,68.15%) at top   ,white 79.5%,transparent 80%) top right;
  -webkit-mask-size:33.4% 140%; 
  -webkit-mask-repeat:no-repeat;
  mask-size:33.4% 140%;
  mask-repeat:no-repeat;
}
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.css">
<section class="hero-container position-relative">
  <div class="container">
    <div class="row">
      <div class="col-md-7 col-xs-12">
        <h1 class="mb-3">Lorem ipsum dolor sit amet</h1>
        <p class="mb-4 text-white">Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet</p>
        <button class="btn btn-secondary">Register My Club</button>
      </div>
    </div>
  </div>
</section>

I will consider the same idea as this previous answer to create the curve using mask and radial-gradient. Simply adjust both variables until you get the needed result:

.box {
  height:300px;
  background: url(https://images.unsplash.com/photo-1581362508717-f542c1ecf295?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1651&q=80) center/cover;
  -webkit-mask:
    radial-gradient(var(--r1,100%) var(--r2,50%) at top   ,white 79.5%,transparent 80%) top left,
    radial-gradient(var(--r1,100%) var(--r2,50%) at bottom,transparent 79.5%,white 80%) top center,
    radial-gradient(var(--r1,100%) var(--r2,50%) at top   ,white 79.5%,transparent 80%) top right;
  mask:
    radial-gradient(var(--r1,100%) var(--r2,50%) at top   ,white 79.5%,transparent 80%) top left,
    radial-gradient(var(--r1,100%) var(--r2,50%) at bottom,transparent 79.5%,white 80%) top center,
    radial-gradient(var(--r1,100%) var(--r2,50%) at top   ,white 79.5%,transparent 80%) top right;
   /* adjust the 150% to control the covered area, the bigger the value the bigger the area will be*/
  -webkit-mask-size:33.4% 150%;
  -webkit-mask-repeat:no-repeat;
  mask-size:33.4% 150%;
  mask-repeat:no-repeat;
}
<div class="box" style="--r1:130%;--r2:71.5%">

</div>

To understand the trick replace the mask with background:

.box {
  height:300px;
  background:
    radial-gradient(var(--r1,100%) var(--r2,50%) at top   ,red 79.5%,transparent 80%)  top left,
    radial-gradient(var(--r1,100%) var(--r2,50%) at bottom,transparent 79.5%,blue 80%) top center,
    radial-gradient(var(--r1,100%) var(--r2,50%) at top   ,red 79.5%,transparent 80%)  top right;
  mask:
    radial-gradient(var(--r1,100%) var(--r2,50%) at top   ,red 79.5%,transparent 80%)  top left,
    radial-gradient(var(--r1,100%) var(--r2,50%) at bottom,transparent 79.5%,blue 80%) top center,
    radial-gradient(var(--r1,100%) var(--r2,50%) at top   ,red 79.5%,transparent 80%)  top right;
  background-size:33.4% 150%;
  background-repeat:no-repeat;
  border:1px solid;
}
<div class="box" style="--r1:130%;--r2:71.5%">

</div>


Applying this to your code:

.hero-container {
  background: url(https://images.unsplash.com/photo-1581362508717-f542c1ecf295?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1651&q=80) top/cover;
  padding: 16.625rem 0;
  -webkit-mask:
    radial-gradient(var(--r1,160%) var(--r2,68.15%) at top   ,white 79.5%,transparent 80%) top left,
    radial-gradient(var(--r1,160%) var(--r2,68.15%) at bottom,transparent 79.5%,white 80%) top center,
    radial-gradient(var(--r1,160%) var(--r2,68.15%) at top   ,white 79.5%,transparent 80%) top right;
  mask:
    radial-gradient(var(--r1,160%) var(--r2,68.15%) at top   ,white 79.5%,transparent 80%) top left,
    radial-gradient(var(--r1,160%) var(--r2,68.15%) at bottom,transparent 79.5%,white 80%) top center,
    radial-gradient(var(--r1,160%) var(--r2,68.15%) at top   ,white 79.5%,transparent 80%) top right;
  -webkit-mask-size:33.4% 140%; 
  -webkit-mask-repeat:no-repeat;
  mask-size:33.4% 140%;
  mask-repeat:no-repeat;
}
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.css">
<section class="hero-container position-relative">
  <div class="container">
    <div class="row">
      <div class="col-md-7 col-xs-12">
        <h1 class="mb-3">Lorem ipsum dolor sit amet</h1>
        <p class="mb-4 text-white">Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet</p>
        <button class="btn btn-secondary">Register My Club</button>
      </div>
    </div>
  </div>
</section>

如何在CSS中实现曲线背景?

櫻之舞 2025-02-18 20:26:01

首先,您的XML应该是良好的。这就是为什么我添加了一个root元素

xml

<root>
    <item>
        <datapoint>5</datapoint>
    </item>
    <item>
        <datapoint>4</datapoint>
    </item>
    <item>
        <datapoint>6</datapoint>
    </item>
    <item>
        <datapoint>8</datapoint>
    </item>
    <item>
        <datapoint>9</datapoint>
    </item>
</root>

xquery

for $x in /root/item[last()-1]/datapoint
return $x

输出

<datapoint>8</datapoint>

First, your XML should be well-formed. That's why I added a root element

XML

<root>
    <item>
        <datapoint>5</datapoint>
    </item>
    <item>
        <datapoint>4</datapoint>
    </item>
    <item>
        <datapoint>6</datapoint>
    </item>
    <item>
        <datapoint>8</datapoint>
    </item>
    <item>
        <datapoint>9</datapoint>
    </item>
</root>

XQuery

for $x in /root/item[last()-1]/datapoint
return $x

Output

<datapoint>8</datapoint>

Xquery找到最后一项

櫻之舞 2025-02-18 07:56:42

我也有一个类似的问题,需要比较不同维度椭圆的拟合错误。以下代码计算每个观测点和椭圆中心之间的角度。然后,它以相同的角度计算观测点和椭圆上的点之间的距离。添加所有点的距离,并通过除以点数来归一化。然后将平均距离除以椭圆的半偏轴,以计算相对于椭圆大小的误差距离。

import math
import numpy as np
from skimage.measure import EllipseModel
from matplotlib.patches import Ellipse
import matplotlib.pyplot as plt

# * * * * * * *
# Calculate the coordinates of the intersection point of the ellipse and the line
# * * * * * * *
def ellipse_line_intersection(Xc, Yc, L, W, phi, theta):
    # Get semimajor and semiminor axes
    a = L / 2
    b = W / 2
    
    # Calculate the parametric equations of the line
    dx = a * np.cos(theta)
    dy = a * np.sin(theta)
    
    # Rotate the line to align the ellipse with the coordinate axes
    cos_phi = np.cos(phi)
    sin_phi = np.sin(phi)
    x1_rot = (dx * cos_phi + dy * sin_phi)
    y1_rot = (-dx * sin_phi + dy * cos_phi)
    
    # Coefficients of the quadratic equation
    A = (x1_rot / a) ** 2 + (y1_rot / b) ** 2
    B = 2 * ((Xc * cos_phi + Yc * sin_phi - Xc * cos_phi - Yc * sin_phi) * x1_rot / a ** 2 + 
             (Xc * sin_phi - Yc * cos_phi - Xc * sin_phi + Yc * cos_phi) * y1_rot / b ** 2)
    C = ((Xc * cos_phi + Yc * sin_phi - Xc * cos_phi - Yc * sin_phi) ** 2 / a ** 2 +
         (Xc * sin_phi - Yc * cos_phi - Xc * sin_phi + Yc * cos_phi) ** 2 / b ** 2) - 1
    
    # Solve the quadratic equation
    discriminant = B ** 2 - 4 * A * C
    if discriminant < 0:
        return []  # No intersection
    
    t1 = (-B + np.sqrt(discriminant)) / (2 * A)
    t2 = (-B - np.sqrt(discriminant)) / (2 * A)
    
    # Calculate the intersection points
    x1 = Xc + dx * t1  # positive root
    y1 = Yc + dy * t1
    x2 = Xc + dx * t2  # negative root
    y2 = Yc + dy * t2
    
    return [(x1, y1), (x2, y2)]

# * * * * * * *
# Main program
# * * * * * * *

x1 = [710.804, 710.117, 709.565, 709.036, 707.839, 707.424, 706.889, 705.913, 705.037, 704.58, 703.758,704.105, 704.552, 704.833, 705.204, 706.027, 706.932, 708.041, 708.849, 709.379, 709.797, 710.272,710.494, 710.871, 711.033, 711.018, 710.804]
y1 = [493.076, 491.902, 491.409, 490.947, 490.396, 491.456, 491.887, 492.917, 494.022, 494.882, 496.085,496.934, 497.723, 498.17, 498.656, 498.929, 499.248, 499.156, 498.768, 498.487, 497.853, 497.212,496.753, 495.957, 495.003, 493.997, 493.076]

points = list(zip(x1,y1))
print(points)
a_points = np.array(points)
n1 = len(a_points)
calc_x = [0]*n1   # coordinates of points along the elliptical curve
calc_y = [0]*n1
x = a_points[:, 0]
y = a_points[:, 1]
ell = EllipseModel()
ell.estimate(a_points)
residuals = ell.residuals(a_points)
xc, yc, a, b, phi = ell.params  # a and b are semimajor and semiminor axes, respectively

print(f' n1={n1}')
ddt = 1  # >0 for debugging
fitting_error = 0

n = 0
distance = 0
sum_of_error_distances = 0
while n < n1:
  x_o = x[n]  # observed x
  y_o = y[n]  # observed y
  # Calculate theta (angle to the observed point) = arctan( (y-yc)/(x-xc) )
  theta = math.atan2( (y_o - yc), (x_o - xc) )
  if theta < 0 :
    theta = math.radians(360) + theta    # correct for quadrants III and IV
  if ddt > 0 :
    print(f'x_o[{n}]={x_o:,.4f} y_o[{n}]={y_o:,.4f} theta={theta:.4f} ({np.rad2deg(theta):.3f} deg.)')

  # calculate predicted intersection point on elliptical curve based on theta
  intersection_points = ellipse_line_intersection(xc, yc, 2*a, 2*b, phi, theta)
  calc_x[n], calc_y[n] = intersection_points[0]  # select only the positive solution
  if ddt > 0: 
    print(f'   calc_x[{n}]={calc_x[n]:.3f}, calc_y[{n}]={calc_y[n]:.3f}')
  # distance between observed and predicted points
  distance = math.sqrt((x_o - calc_x[n])**2 + (y_o - calc_y[n])**2)  
  sum_of_error_distances += distance

  n = n + 1

average_error_distance = sum_of_error_distances/n
print(f'Average error distance = {average_error_distance:.4f}')
fitting_error = average_error_distance*100/b
# Percent average error distance relative to minor axis 
print(f'Fitting error = {fitting_error:.4f}%')

print("center = ",  (xc, yc))
print("angle of rotation = ", phi)
print("axes = ", (a,b))
print('residuals= ', residuals)
fig, axs = plt.subplots(2, 1, sharex=True, sharey=True)
axs[0].scatter(x,y)
axs[1].scatter(x, y)
axs[1].plot(calc_x, calc_y, 'x')
axs[1].scatter(xc, yc, color='red', s=100)
axs[1].set_xlim(x.min(), x.max())
axs[1].set_ylim(y.min(), y.max())
axs[0].set_title(f' points: {n1}, fitting error: {fitting_error:.3f}%')
ell_patch = Ellipse(xy=(xc, yc), width=2*a, height=2*b, angle=phi*180/np.pi, edgecolor='red', facecolor='none')
axs[1].add_patch(ell_patch)
plt.show()

带有拟合错误的椭圆形

I had a similar problem that required comparing the fitting errors of ellipses of different dimensions. The following code calculates the angle between each observed point and the center of the ellipse. Then, it calculates the distance between the observed point and a point on the ellipse at the same angle. The distances are added for all the points and normalized by dividing by the number of points. The average distance is then divided by the semiminor axis of the ellipse to calculate the error distance relative to the size of the ellipse.

import math
import numpy as np
from skimage.measure import EllipseModel
from matplotlib.patches import Ellipse
import matplotlib.pyplot as plt

# * * * * * * *
# Calculate the coordinates of the intersection point of the ellipse and the line
# * * * * * * *
def ellipse_line_intersection(Xc, Yc, L, W, phi, theta):
    # Get semimajor and semiminor axes
    a = L / 2
    b = W / 2
    
    # Calculate the parametric equations of the line
    dx = a * np.cos(theta)
    dy = a * np.sin(theta)
    
    # Rotate the line to align the ellipse with the coordinate axes
    cos_phi = np.cos(phi)
    sin_phi = np.sin(phi)
    x1_rot = (dx * cos_phi + dy * sin_phi)
    y1_rot = (-dx * sin_phi + dy * cos_phi)
    
    # Coefficients of the quadratic equation
    A = (x1_rot / a) ** 2 + (y1_rot / b) ** 2
    B = 2 * ((Xc * cos_phi + Yc * sin_phi - Xc * cos_phi - Yc * sin_phi) * x1_rot / a ** 2 + 
             (Xc * sin_phi - Yc * cos_phi - Xc * sin_phi + Yc * cos_phi) * y1_rot / b ** 2)
    C = ((Xc * cos_phi + Yc * sin_phi - Xc * cos_phi - Yc * sin_phi) ** 2 / a ** 2 +
         (Xc * sin_phi - Yc * cos_phi - Xc * sin_phi + Yc * cos_phi) ** 2 / b ** 2) - 1
    
    # Solve the quadratic equation
    discriminant = B ** 2 - 4 * A * C
    if discriminant < 0:
        return []  # No intersection
    
    t1 = (-B + np.sqrt(discriminant)) / (2 * A)
    t2 = (-B - np.sqrt(discriminant)) / (2 * A)
    
    # Calculate the intersection points
    x1 = Xc + dx * t1  # positive root
    y1 = Yc + dy * t1
    x2 = Xc + dx * t2  # negative root
    y2 = Yc + dy * t2
    
    return [(x1, y1), (x2, y2)]

# * * * * * * *
# Main program
# * * * * * * *

x1 = [710.804, 710.117, 709.565, 709.036, 707.839, 707.424, 706.889, 705.913, 705.037, 704.58, 703.758,704.105, 704.552, 704.833, 705.204, 706.027, 706.932, 708.041, 708.849, 709.379, 709.797, 710.272,710.494, 710.871, 711.033, 711.018, 710.804]
y1 = [493.076, 491.902, 491.409, 490.947, 490.396, 491.456, 491.887, 492.917, 494.022, 494.882, 496.085,496.934, 497.723, 498.17, 498.656, 498.929, 499.248, 499.156, 498.768, 498.487, 497.853, 497.212,496.753, 495.957, 495.003, 493.997, 493.076]

points = list(zip(x1,y1))
print(points)
a_points = np.array(points)
n1 = len(a_points)
calc_x = [0]*n1   # coordinates of points along the elliptical curve
calc_y = [0]*n1
x = a_points[:, 0]
y = a_points[:, 1]
ell = EllipseModel()
ell.estimate(a_points)
residuals = ell.residuals(a_points)
xc, yc, a, b, phi = ell.params  # a and b are semimajor and semiminor axes, respectively

print(f' n1={n1}')
ddt = 1  # >0 for debugging
fitting_error = 0

n = 0
distance = 0
sum_of_error_distances = 0
while n < n1:
  x_o = x[n]  # observed x
  y_o = y[n]  # observed y
  # Calculate theta (angle to the observed point) = arctan( (y-yc)/(x-xc) )
  theta = math.atan2( (y_o - yc), (x_o - xc) )
  if theta < 0 :
    theta = math.radians(360) + theta    # correct for quadrants III and IV
  if ddt > 0 :
    print(f'x_o[{n}]={x_o:,.4f} y_o[{n}]={y_o:,.4f} theta={theta:.4f} ({np.rad2deg(theta):.3f} deg.)')

  # calculate predicted intersection point on elliptical curve based on theta
  intersection_points = ellipse_line_intersection(xc, yc, 2*a, 2*b, phi, theta)
  calc_x[n], calc_y[n] = intersection_points[0]  # select only the positive solution
  if ddt > 0: 
    print(f'   calc_x[{n}]={calc_x[n]:.3f}, calc_y[{n}]={calc_y[n]:.3f}')
  # distance between observed and predicted points
  distance = math.sqrt((x_o - calc_x[n])**2 + (y_o - calc_y[n])**2)  
  sum_of_error_distances += distance

  n = n + 1

average_error_distance = sum_of_error_distances/n
print(f'Average error distance = {average_error_distance:.4f}')
fitting_error = average_error_distance*100/b
# Percent average error distance relative to minor axis 
print(f'Fitting error = {fitting_error:.4f}%')

print("center = ",  (xc, yc))
print("angle of rotation = ", phi)
print("axes = ", (a,b))
print('residuals= ', residuals)
fig, axs = plt.subplots(2, 1, sharex=True, sharey=True)
axs[0].scatter(x,y)
axs[1].scatter(x, y)
axs[1].plot(calc_x, calc_y, 'x')
axs[1].scatter(xc, yc, color='red', s=100)
axs[1].set_xlim(x.min(), x.max())
axs[1].set_ylim(y.min(), y.max())
axs[0].set_title(f' points: {n1}, fitting error: {fitting_error:.3f}%')
ell_patch = Ellipse(xy=(xc, yc), width=2*a, height=2*b, angle=phi*180/np.pi, edgecolor='red', facecolor='none')
axs[1].add_patch(ell_patch)
plt.show()

ellipse with Fitting error

我该如何得分椭圆形的适合能力?

櫻之舞 2025-02-17 21:01:07

好的,我在关于隐藏输入字段值的评论中是错误的。
我的意思是,这仍然是一个问题,但是除了您制作的JS代码错误外,它应该运行原样。

因此,首先,给我错误的印象是,您通常会根据我的要求提交一张表格,然后按照我的说法正确设置表格值,以便在提交时提供请求的数据。您制作了很多形式,一种是每次迭代的形式,这不是错误的,但是您所做的就是在OnClick事件中说,以始终激活网站上的第一种形式。即

document.forms[0]

,无论您单击什么,都将仅提交使用第一个隐藏输入字段的值。

如您所拥有的IF-ELSE条款,我不会依赖DOM中的表单索引,而是使用某些内容来创建每种表单唯一的ID,然后使用document.getElementById()获取确切的表单并提交。但是您已经给出了表格名称,因此您可以使用document.getElementsByname()或给出相同值的表单。
名称不需要唯一,ID应该。

只是一个小样本:

<form id="siCompeticion"+{{competicionAPI['id']}} ...>
    <input type="hidden" name="something" value={{competicionAPI['id']}}>
    <a href="#" onclick="javascript:document.getElementById("siCompeticion"+{{competicionAPI['id']}}).submit();return false;">CLICK ME</a>
</form>

在您的位置,我很可能会编写一些JS代码来执行Ajax请求,这很可能是使用jQuery。无论如何,我都会避免做出很多形式。

OK, I was wrong in a comment about hidden input field value being a problem.
I mean, it is still a problem, but it should work as is, except for JS code bug you made.

So first, what gave me wrong impression was that you would usually make one form per request, and then do as I said, set the forms values correctly to provide data of the request upon submit. You made a lot of forms, one per iteration, which is not wrong, but what you did is say in onclick event to activate always the first form on the site. I.e.

document.forms[0]

so, whatever you click, only first form will be submitted with the value of the first hidden input field in it.

As you have if-else clauses, I wouldn't rely on form indexes within the DOM, but use something to create unique IDs per each form, then use document.getElementById() to get that exact form and submit it. But you already gave your forms names, so you can use those with document.getElementsByName() or give the form an ID of same value.
Names does not need to be unique, IDs should.

Just a little sample:

<form id="siCompeticion"+{{competicionAPI['id']}} ...>
    <input type="hidden" name="something" value={{competicionAPI['id']}}>
    <a href="#" onclick="javascript:document.getElementById("siCompeticion"+{{competicionAPI['id']}}).submit();return false;">CLICK ME</a>
</form>

In your place I would most probably write a little JS code to perform AJAX request, most likely using jquery. In any case, I would avoid making a lot of forms.

html&amp; Python-用于循环和动态形式创建

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文